Conrad Meyer replaces our expat-based XML reader with QtXmlStreamReader.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 5 Aug 2013 03:49:56 +0000 (03:49 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 5 Aug 2013 03:49:56 +0000 (03:49 +0000)
This is known to crash right now, and that will anger Jenkins, but this will only hurt for a
little while.  (I hope.)   The changes are too good to leave unmerged - let's tackle them
together.

29 files changed:
gpsbabel/coastexp.cc
gpsbabel/defs.h
gpsbabel/dmtlog.cc
gpsbabel/garmin_device_xml.cc
gpsbabel/glogbook.cc
gpsbabel/google.cc
gpsbabel/googledir.cc
gpsbabel/gpx.cc
gpsbabel/gtrnctr.cc
gpsbabel/hiketech.cc
gpsbabel/ignrando.cc
gpsbabel/ik3d.cc
gpsbabel/jogmap.cc
gpsbabel/kml.cc
gpsbabel/lmx.cc
gpsbabel/maggeo.cc
gpsbabel/main.cc
gpsbabel/osm.cc
gpsbabel/pocketfms_fp.cc
gpsbabel/reference/google-direction.gpx
gpsbabel/reference/google.csv
gpsbabel/tef_xml.cc
gpsbabel/trackfilter.cc
gpsbabel/util.cc
gpsbabel/wfff_xml.cc
gpsbabel/xmlgeneric.cc
gpsbabel/xmlgeneric.h
gpsbabel/xol.cc
gpsbabel/yahoo.cc

index 0ac07e8cda1928060805d7d055680e0612711553..5c2e3ade67ce2423faebfecfa7da2b8d2ae13200 100644 (file)
@@ -18,6 +18,8 @@
 
  */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 #if HAVE_LIBEXPAT
index 33529610f104299effa7cb84bc855b428ec9e400..cbeb2b10bbf172a96f62ded93594cda14a3085d8 100644 (file)
 #  define XML_UNICODE
 #endif
 
+#define CSTR(qstr) (qstr.toUtf8().constData())
+#define CSTRE_(qstr, enc) (enc->fromUnicode(qstr).constData())
+#define CSTRE(qstr) (CSTRE_(qstr, codec))
+
 /*
  * Amazingly, this constant is not specified in the standard...
  */
index f886b51202eec98b026059d19afa49bfd87007a7..04a46e30490464990e96c65d0addb82de6207efe 100644 (file)
@@ -20,6 +20,8 @@
 
  */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "jeeps/gpsmath.h"
 #include "xmlgeneric.h"
@@ -146,7 +148,7 @@ finalize_pt(waypoint* wpt)
 
 #if !ZLIB_INHIBITED
 static void
-tlog3a_xgcb_version(const char* args, const char** unused)
+tlog3a_xgcb_version(const char* args, const QXmlStreamAttributes* unused)
 {
   if (strcmp(args, "1") != 0) {
     fatal(MYNAME ": Unsupported file version '%s'!\n", args);
@@ -154,12 +156,12 @@ tlog3a_xgcb_version(const char* args, const char** unused)
 }
 
 static void
-tlog3a_xgcb_length(const char* args, const char** unused)
+tlog3a_xgcb_length(const char* args, const QXmlStreamAttributes* unused)
 {
 }
 
 static void
-tlog3a_xgcb_data(const char* args, const char** unused)
+tlog3a_xgcb_data(const char* args, const QXmlStreamAttributes* unused)
 {
   int len;
   char* bin;
@@ -203,7 +205,7 @@ tlog3a_xgcb_data(const char* args, const char** unused)
 
 
 static void
-tlog3b_xgcb_tfna(const char* args, const char** unused)
+tlog3b_xgcb_tfna(const char* args, const QXmlStreamAttributes* unused)
 {
   if (xmltrk == NULL) {
     xmltrk = route_head_alloc();
@@ -214,7 +216,7 @@ tlog3b_xgcb_tfna(const char* args, const char** unused)
 
 
 static void
-tlog3b_xgcb_tfdes(const char* args, const char** unused)
+tlog3b_xgcb_tfdes(const char* args, const QXmlStreamAttributes* unused)
 {
   if (xmltrk == NULL) {
     xmltrk = route_head_alloc();
@@ -225,7 +227,7 @@ tlog3b_xgcb_tfdes(const char* args, const char** unused)
 
 
 static void
-tlog3b_xgcb_wptst(const char* args, const char** unused)
+tlog3b_xgcb_wptst(const char* args, const QXmlStreamAttributes* unused)
 {
   xmlwpt = waypt_new();
   xmldatum = DATUM_WGS84;
@@ -233,7 +235,7 @@ tlog3b_xgcb_wptst(const char* args, const char** unused)
 
 
 static void
-tlog3b_xgcb_tptst(const char* args, const char** unused)
+tlog3b_xgcb_tptst(const char* args, const QXmlStreamAttributes* unused)
 {
   xmlwpt = waypt_new();
   xmldatum = DATUM_WGS84;
@@ -241,7 +243,7 @@ tlog3b_xgcb_tptst(const char* args, const char** unused)
 
 
 static void
-tlog3b_xgcb_tpten(const char* args, const char** unused)
+tlog3b_xgcb_tpten(const char* args, const QXmlStreamAttributes* unused)
 {
   finalize_pt(xmlwpt);
 
@@ -255,7 +257,7 @@ tlog3b_xgcb_tpten(const char* args, const char** unused)
 
 
 static void
-tlog3b_xgcb_wptid(const char* args, const char** unused)
+tlog3b_xgcb_wptid(const char* args, const QXmlStreamAttributes* unused)
 {
   if (*args) {
     xmlwpt->shortname = xstrdup(args);
@@ -264,14 +266,14 @@ tlog3b_xgcb_wptid(const char* args, const char** unused)
 
 
 static void
-tlog3b_xgcb_wptdt(const char* args, const char** unused)
+tlog3b_xgcb_wptdt(const char* args, const QXmlStreamAttributes* unused)
 {
   xmldatum = GPS_Lookup_Datum_Index(args);
 }
 
 
 static void
-tlog3b_xgcb_wptgr(const char* args, const char** unused)
+tlog3b_xgcb_wptgr(const char* args, const QXmlStreamAttributes* unused)
 {
   if (xmlgrid != NULL) {
     if (strcmp(xmlgrid, args) == 0) {
@@ -284,35 +286,35 @@ tlog3b_xgcb_wptgr(const char* args, const char** unused)
 
 
 static void
-tlog3b_xgcb_wptno(const char* args, const char** unused)
+tlog3b_xgcb_wptno(const char* args, const QXmlStreamAttributes* unused)
 {
   xmlNorthing = atof(args);
 }
 
 
 static void
-tlog3b_xgcb_wptea(const char* args, const char** unused)
+tlog3b_xgcb_wptea(const char* args, const QXmlStreamAttributes* unused)
 {
   xmlEasting = atof(args);
 }
 
 
 static void
-tlog3b_xgcb_wptal(const char* args, const char** unused)
+tlog3b_xgcb_wptal(const char* args, const QXmlStreamAttributes* unused)
 {
   xmlAltitude = atof(args);
 }
 
 
 static void
-tlog3b_xgcb_tptdt(const char* args, const char** unused)
+tlog3b_xgcb_tptdt(const char* args, const QXmlStreamAttributes* unused)
 {
   xmldatum = GPS_Lookup_Datum_Index(args);
 }
 
 
 static void
-tlog3b_xgcb_wpten(const char* args, const char** unused)
+tlog3b_xgcb_wpten(const char* args, const QXmlStreamAttributes* unused)
 {
   finalize_pt(xmlwpt);
   waypt_add(xmlwpt);
index 8630ada61663d49e47c61d303035fd8fcf929842..e5767c25a52822bbc6b57a73aae160be4e888f87 100644 (file)
@@ -24,6 +24,8 @@
 // http://developer.garmin.com/web-device/garmin-mass-storage-mode-devices/
 // http://developer.garmin.com/schemas/device/v2/
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 #include "garmin_device_xml.h"
@@ -36,12 +38,12 @@ static char* mountpoint, *base, *path, *ext;
 static xg_callback device_s, id_s, path_s, ext_s, base_s, dir_s;
 jmp_buf gdx_jmp_buf;
 
-void type_s(const char* args, const char** unused)
+void type_s(const char* args, const QXmlStreamAttributes* unused)
 {
   type = strcmp(args, "GPSData");
 }
 
-void device_s(const char* args, const char** unused)
+void device_s(const char* args, const QXmlStreamAttributes* unused)
 {
   if (my_gdx_info) {
     fatal(MYNAME ": More than one device type found in file.\n");
@@ -50,27 +52,27 @@ void device_s(const char* args, const char** unused)
   my_gdx_info->device_desc = xstrdup(args);
 }
 
-void id_s(const char* args, const char** unused)
+void id_s(const char* args, const QXmlStreamAttributes* unused)
 {
   my_gdx_info->device_id = xstrdup(args);
 }
 
-void path_s(const char* args, const char** unused)
+void path_s(const char* args, const QXmlStreamAttributes* unused)
 {
   path = xstrdup(args);
 }
 
-void ext_s(const char* args, const char** unused)
+void ext_s(const char* args, const QXmlStreamAttributes* unused)
 {
   ext = xstrdup(args);
 }
 
-void base_s(const char* args, const char** unused)
+void base_s(const char* args, const QXmlStreamAttributes* unused)
 {
   base = xstrdup(args);
 }
 
-void dir_s(const char* args, const char** unused)
+void dir_s(const char* args, const QXmlStreamAttributes* unused)
 {
   if (type) {
     return;
index 8e91cbc9e4feb949fcbd4ada12bc95e350c639b0..fed772e6370e659e9960f2fefbd6f1aa9b30ab07 100644 (file)
@@ -19,6 +19,8 @@
 
  */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -124,44 +126,44 @@ glogbook_write(void)
   gbfprintf(ofd, "</History>\n");
 }
 
-void   gl_trk_s(const char* args, const char** unused)
+void   gl_trk_s(const char* args, const QXmlStreamAttributes* unused)
 {
   trk_head = route_head_alloc();
   track_add_head(trk_head);
 }
 #if 0
-void   gl_trk_ident(const char* args, const char** unused)
+void   gl_trk_ident(const char* args, const QXmlStreamAttributes* unused)
 {
   trk_head->rte_name = xstrdup(args);
 }
 #endif
 
-void   gl_trk_pnt_s(const char* args, const char** unused)
+void   gl_trk_pnt_s(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp = waypt_new();
 }
 
-void   gl_trk_pnt_e(const char* args, const char** unused)
+void   gl_trk_pnt_e(const char* args, const QXmlStreamAttributes* unused)
 {
   track_add_wpt(trk_head, wpt_tmp);
 }
 
-void   gl_trk_utc(const char* args, const char** unused)
+void   gl_trk_utc(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->SetCreationTime(xml_parse_time(args));
 }
 
-void   gl_trk_lat(const char* args, const char** unused)
+void   gl_trk_lat(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->latitude = atof(args);
 }
 
-void   gl_trk_long(const char* args, const char** unused)
+void   gl_trk_long(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->longitude = atof(args);
 }
 
-void   gl_trk_alt(const char* args, const char** unused)
+void   gl_trk_alt(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->altitude = atof(args);
 }
index 806da6a59a9bab8a3910b8316d1a95b0e4269f54..6e0efee745d20ae69dfed857168999059c262fe7 100644 (file)
@@ -16,6 +16,9 @@
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
 
  */
+
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -65,7 +68,7 @@ xg_tag_mapping google_map[] = {
   { NULL, (xg_cb_type)0,              NULL }
 };
 
-void goog_script(const char* args, const char** unused)
+void goog_script(const char* args, const QXmlStreamAttributes *unused)
 {
   if (args) {
     if (script) {
@@ -76,7 +79,7 @@ void goog_script(const char* args, const char** unused)
   }
 }
 
-void goog_points(const char* args, const char** unused)
+void goog_points(const char* args, const QXmlStreamAttributes *unused)
 {
   if (args) {
     if (encoded_points) {
@@ -87,7 +90,7 @@ void goog_points(const char* args, const char** unused)
   }
 }
 
-void goog_levels(const char* args, const char** unused)
+void goog_levels(const char* args, const QXmlStreamAttributes *unused)
 {
   if (args) {
     if (encoded_levels) {
@@ -106,59 +109,64 @@ static int goog_segroute = 0;
  * The segments contain an index into the points array.  We use that
  * index to find the waypoint and insert a better name for it.
  */
-void goog_segment_s(const char* args, const char** attrv)
+void goog_segment_s(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
-  while (*avp) {
-    if (0 == strcmp(avp[0], "pointIndex")) {
-      snprintf(goog_segname, sizeof(goog_segname), "\\%5.5x", atoi(avp[1]));
-    }
-    avp += 2;
+  QStringRef ptidx = attrv->value("pointIndex");
+  if (!ptidx.isEmpty()) {
+    snprintf(goog_segname, sizeof(goog_segname), "\\%5.5x",
+        ptidx.toString().toUInt());
   }
-
 }
 
-void goog_segment(const char* args, const char** unused)
+void goog_segment(const char* args, const QXmlStreamAttributes *unused)
 {
   waypoint* wpt_tmp;
 
   wpt_tmp = route_find_waypt_by_name(routehead[goog_segroute], goog_segname);
   if (wpt_tmp) {
     xfree(wpt_tmp->shortname);
-    wpt_tmp->shortname = mkshort(desc_handle,args);
+    wpt_tmp->shortname = mkshort(desc_handle, args);
     wpt_tmp->description = xstrdup(args);
   }
 }
 
-void goog_td_s(const char* args, const char** attrv)
+void goog_td_s(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
-  int isdesc = 0;
-  int isseg = 0;
-  while (*avp) {
-    if (0 == strcmp(avp[0], "class")) {
-      isdesc = !strcmp(avp[1], "desc");
-      isseg = !strcmp(avp[1], "dirsegtext");
-    } else if (isdesc && (0 == strcmp(avp[0], "id"))) {
-      goog_segroute = 0;
-      snprintf(goog_segname, sizeof(goog_segname),
-               "\\%5.5x",
-               atoi(avp[1] + 6));
-    } else if (isseg && (0 == strcmp(avp[0], "id"))) {
-      if (strchr(strchr(avp[1],'_')+1,'_')) {
-        goog_segroute = atoi(strchr(avp[1],'_')+1);
-      } else {
-        goog_segroute = 0;
-      }
-      snprintf(goog_segname, sizeof(goog_segname),
-               "\\%5.5x",
-               atoi(strrchr(avp[1],'_') + 1)+routecount[goog_segroute]);
+  bool isdesc = false, isseg = false;
+  QStringRef aclass = attrv->value("class");
+  QStringRef id = attrv->value("id");
+
+  if (aclass.isEmpty() || id.isEmpty()) {
+    return;
+  }
+
+  isdesc = (aclass == "desc");
+  isseg = (aclass == "dirsegtext");
+
+  if (isdesc) {
+    QStringRef subid(id.string(), id.position() + 6, id.length() - 6);
+
+    goog_segroute = 0;
+    snprintf(goog_segname, sizeof(goog_segname), "\\%5.5x",
+             subid.toString().toUInt());
+  } else if (isseg) {
+    QString idstr = id.toString();
+    int first_us;
+
+    goog_segroute = 0;
+
+    first_us = idstr.indexOf("_");
+    if (idstr.indexOf("_", first_us + 1) != -1) {
+      goog_segroute = idstr.mid(first_us + 1).toUInt();
     }
-    avp += 2;
+
+    snprintf(goog_segname, sizeof(goog_segname), "\\%5.5x",
+             idstr.mid(idstr.lastIndexOf("_") + 1).toUInt() +
+               routecount[goog_segroute]);
   }
 }
 
-void goog_td_b(const char* args, const char** attrv)
+void goog_td_b(const char* args, const QXmlStreamAttributes* unused)
 {
   if (goog_segname[0] == '\\' && !strchr(args, '\xa0')) {
     if (goog_realname) {
@@ -169,10 +177,10 @@ void goog_td_b(const char* args, const char** attrv)
     strcpy(goog_realname, args);
   }
 }
-void goog_td_e(const char* args, const char** attrv)
+void goog_td_e(const char* args, const QXmlStreamAttributes* unused)
 {
   if (goog_segname[0] == '\\' && goog_realname) {
-    goog_segment(goog_realname, attrv);
+    goog_segment(goog_realname, NULL/*unused*/);
   }
   goog_segname[0] = '\0';
   if (goog_realname) {
@@ -203,7 +211,7 @@ static long decode_goog64(char** str)
   return result/2;
 }
 
-void goog_poly_e(const char* args, const char** unused)
+void goog_poly_e(const char* args, const QXmlStreamAttributes *unused)
 {
   long lat = 0;
   long lon = 0;
@@ -254,7 +262,7 @@ google_rd_init(const char* fname)
   desc_handle = mkshort_new_handle();
   setshort_length(desc_handle, 12);
 
-  xml_init(fname, google_map, "ISO-8859-1");
+  xml_init(fname, google_map, NULL);
 }
 
 static void
index 6268294b8b67620ffb6a22be0773947e79acbe58..18843feb9a3404747b7044b3167033cfa6133501 100644 (file)
@@ -24,6 +24,9 @@
  * For more information, check:
  * https://developers.google.com/maps/documentation/directions/
  */
+
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -34,19 +37,6 @@ static short_handle desc_handle;
 #define MYNAME "googledir"
 #define MY_CBUF 4096
 
-#if ! HAVE_LIBEXPAT
-static void
-google_rd_init(const char* fname)
-{
-  fatal(MYNAME ": This build excluded Google Maps support because expat was not installed.\n");
-}
-
-static void
-google_read(void)
-{
-}
-#else
-
 static xg_callback      goog_points, goog_poly_e;
 static xg_callback      goog_instr;
 
@@ -61,7 +51,7 @@ xg_tag_mapping google_map[] = {
 };
 
 void
-goog_points(const char* args, const char** unused)
+goog_points(const char* args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     if (encoded_points) {
@@ -73,7 +63,7 @@ goog_points(const char* args, const char** unused)
 }
 
 void
-goog_instr(const char* args, const char** unused)
+goog_instr(const char* args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     if (instructions) {
@@ -110,7 +100,7 @@ decode_goog64(char** str)
 }
 
 static void
-goog_poly_e(const char* args, const char** unused)
+goog_poly_e(const char* args, const QXmlStreamAttributes* unused)
 {
   long lat = 0;
   long lon = 0;
@@ -121,18 +111,18 @@ goog_poly_e(const char* args, const char** unused)
     routehead->rte_name = (char*) xstrdup("overview");
     routehead->rte_desc = (char*) xstrdup("Overview");
   } else {
-       goog_step++;
+    goog_step++;
     xasprintf(&routehead->rte_name, "step%03d", goog_step);
     if (instructions == NULL) {
       xasprintf(&routehead->rte_desc, "Step %d", goog_step);
     } else {
       utf_string utf;
       utf.is_html = 1;
-      utf.utfstring = instructions;
+      utf.utfstring = QString::fromUtf8(instructions);
       routehead->rte_desc = strip_html(&utf);
       xfree(instructions);
       instructions = NULL;
-       }
+    }
   }
   route_add_head(routehead);
 
@@ -167,7 +157,8 @@ google_rd_init(const char* fname)
   desc_handle = mkshort_new_handle();
   setshort_length(desc_handle, 12);
 
-  xml_init(fname, google_map, "ISO-8859-1");
+  // leave default of UTF-8 unless xml file overrides with encoding=
+  xml_init(fname, google_map, NULL);
 }
 
 static void
@@ -184,7 +175,6 @@ google_read(void)
     instructions = NULL;
   }
 }
-#endif
 
 static void
 google_rd_deinit(void)
index daab6eba84bb06dcc87a496534499cb2bae62af0..5d1d601dfbc75d7b506a7cad112a19678e720e17 100644 (file)
@@ -1344,21 +1344,9 @@ gpx_wr_init(const char* fname)
   ofd = gbfopen(fname, "wb", MYNAME);
   oqfile.open(ofd->handle.std, QIODevice::WriteOnly);
 
-  // This is ia bit of a lie.  QXMLStreamWriter will pass everything
-  // through the QTextCodec on the way out and that defaults to UTF-8.
-  // Since we have so many C Strings in out output right now and those
-  // are already UTF-8 encoded via CET, if we don't outsmart that, we
-  // get double encoding.
-  writer.setCodec("ISO 8859-1");
-
   writer.setAutoFormattingIndent(2);
-  // Technically, XML (and therefore GPX) defaults ot UTF-8, so we should not
-  // have to declare this.  For compatibility with the existing Qt writer,
-  // we do...
-  //  writer.setCodec("UTF-8");
-  //  writer.writeStartDocument();
-  writer.writeProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
-
+  writer.setCodec("UTF-8");
+  writer.writeStartDocument();
 }
 
 static void
@@ -1650,16 +1638,16 @@ gpx_write_common_description(const waypoint* waypointp, QString oname)
   // file.  Filter that out in the two fields below... Ideally, we should
   // probably filter that in the input rather than here.
 
-  QString desc = waypointp->description;
+  QString desc = QString::fromUtf8(waypointp->description);
   desc = desc.replace(QRegExp("[\014-\032]"), " ");
   writer.writeOptionalTextElement("cmt", desc);
 
   if (waypointp->notes && waypointp->notes[0]) {
-    QString note = waypointp->notes;
+    QString note = QString::fromUtf8(waypointp->notes);
     note = note.replace(QRegExp("[\014-\032]"), " ");
     writer.writeTextElement("desc", note);
   } else {
-    writer.writeOptionalTextElement("desc", waypointp->description);
+    writer.writeOptionalTextElement("desc", QString::fromUtf8(waypointp->description));
   }
 
   write_gpx_url(waypointp);
@@ -1709,8 +1697,8 @@ gpx_track_hdr(const route_head* rte)
   current_trk_head = rte;
 
   writer.writeStartElement("trk");
-  writer.writeOptionalTextElement("name", rte->rte_name);
-  writer.writeOptionalTextElement("desc", rte->rte_desc);
+  writer.writeOptionalTextElement("name", QString::fromUtf8(rte->rte_name));
+  writer.writeOptionalTextElement("desc", QString::fromUtf8(rte->rte_desc));
   if (rte->rte_num) {
     writer.writeTextElement("number", QString::number(rte->rte_num));
   }
@@ -1801,8 +1789,8 @@ gpx_route_hdr(const route_head* rte)
 {
   fs_xml* fs_gpx;
   writer.writeStartElement("rte");
-  writer.writeOptionalTextElement("name", rte->rte_name);
-  writer.writeOptionalTextElement("desc", rte->rte_desc);
+  writer.writeOptionalTextElement("name", QString::fromUtf8(rte->rte_name));
+  writer.writeOptionalTextElement("desc", QString::fromUtf8(rte->rte_desc));
 
   if (rte->rte_num) {
     writer.writeTextElement("number", QString::number(rte->rte_num));
index 62b16d0e1d1f05076a3357ab9311bb6159e388f3..539367e34bfbcf1842a17f6912f7a51502538962 100644 (file)
@@ -19,6 +19,8 @@
 
  */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -462,39 +464,39 @@ gtc_write(void)
 }
 
 void
-gtc_trk_s(const char* unused, const char** attrv)
+gtc_trk_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
 {
   trk_head = route_head_alloc();
   track_add_head(trk_head);
 }
 
 void
-gtc_trk_ident(const char* args, const char** unused)
+gtc_trk_ident(const char* args, const QXmlStreamAttributes* unused)
 {
   trk_head->rte_name = xstrdup(args);
 }
 
 void
-gtc_trk_lap_s(const char* unused, const char** attrv)
+gtc_trk_lap_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
 {
   lap_ct++;
   lap_s = 1;
 }
 
 void
-gtc_trk_lap_e(const char* unused, const char** attrv)
+gtc_trk_lap_e(const char* unused, const QXmlStreamAttributes* unusedattrs)
 {
   lap_s = 0;
 }
 
 void
-gtc_trk_pnt_s(const char* unused, const char** attrv)
+gtc_trk_pnt_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
 {
   wpt_tmp = waypt_new();
 }
 
 void
-gtc_trk_pnt_e(const char* args, const char** unused)
+gtc_trk_pnt_e(const char* args, const QXmlStreamAttributes* unusedd)
 {
   if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) {
     if (lap_s) {
@@ -517,67 +519,67 @@ gtc_trk_pnt_e(const char* args, const char** unused)
 }
 
 void
-gtc_trk_utc(const char* args, const char** unused)
+gtc_trk_utc(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->creation_time = xml_parse_time(args);
 }
 
 void
-gtc_trk_lat(const char* args, const char** unused)
+gtc_trk_lat(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->latitude = atof(args);
 }
 
 void
-gtc_trk_long(const char* args, const char** unused)
+gtc_trk_long(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->longitude = atof(args);
 }
 
 void
-gtc_trk_alt(const char* args, const char** unused)
+gtc_trk_alt(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->altitude = atof(args);
 }
 
 void
-gtc_trk_dist(const char* args, const char** unused)
+gtc_trk_dist(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->odometer_distance = atof(args);
 }
 
 void
-gtc_trk_hr(const char* args, const char** unused)
+gtc_trk_hr(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->heartrate = atoi(args);
 }
 
 void
-gtc_trk_cad(const char* args, const char** unused)
+gtc_trk_cad(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->cadence = atoi(args);
 }
 
 void
-gtc_trk_pwr(const char* args, const char** unused)
+gtc_trk_pwr(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->power = atof(args);
 }
 
 void
-gtc_trk_spd(const char* args, const char** unused)
+gtc_trk_spd(const char* args, const QXmlStreamAttributes* unusedd)
 {
   WAYPT_SET(wpt_tmp, speed, atof(args));
 }
 
 void
-gtc_wpt_crs_s(const char* unused, const char** attrv)
+gtc_wpt_crs_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
 {
   wpt_tmp = waypt_new();
 }
 
 void
-gtc_wpt_crs_e(const char* args, const char** unused)
+gtc_wpt_crs_e(const char* args, const QXmlStreamAttributes* unusedd)
 {
   if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) {
     waypt_add(wpt_tmp);
@@ -589,14 +591,14 @@ gtc_wpt_crs_e(const char* args, const char** unused)
 }
 
 void
-gtc_wpt_pnt_s(const char* unused, const char** attrv)
+gtc_wpt_pnt_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
 {
   wpt_tmp = waypt_new();
   lap_ct++;
 }
 
 void
-gtc_wpt_pnt_e(const char* args, const char** unused)
+gtc_wpt_pnt_e(const char* args, const QXmlStreamAttributes* unusedd)
 {
   if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) {
     /* Add the begin position of a CourseLap as
@@ -613,7 +615,7 @@ gtc_wpt_pnt_e(const char* args, const char** unused)
 }
 
 void
-gtc_wpt_ident(const char* args, const char** unused)
+gtc_wpt_ident(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->shortname = xstrdup(args);
   /* Set also as notes for compatibility with garmin usb format */
@@ -621,25 +623,25 @@ gtc_wpt_ident(const char* args, const char** unused)
 }
 
 void
-gtc_wpt_lat(const char* args, const char** unused)
+gtc_wpt_lat(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->latitude = atof(args);
 }
 
 void
-gtc_wpt_long(const char* args, const char** unused)
+gtc_wpt_long(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->longitude = atof(args);
 }
 
 void
-gtc_wpt_icon(const char* args, const char** unused)
+gtc_wpt_icon(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->icon_descr = args;
 }
 
 void
-gtc_wpt_notes(const char* args, const char** unused)
+gtc_wpt_notes(const char* args, const QXmlStreamAttributes* unusedd)
 {
   wpt_tmp->description = xstrdup(args);
 }
index 019f4366479a3b5aa4bf69e57028e7dcefdca314..13c3a720260eda257ca4440c87afa4a6e63464bf 100644 (file)
@@ -19,6 +19,8 @@
 
  */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -170,81 +172,81 @@ hiketech_write(void)
 }
 
 static
-void    ht_wpt_s(const char* args, const char** unused)
+void    ht_wpt_s(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp = waypt_new();
 }
 
 static
-void   ht_ident(const char* args, const char** unused)
+void   ht_ident(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->shortname = xstrdup(args);
 }
 
 static
-void   ht_sym(const char* args, const char** unused)
+void   ht_sym(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->icon_descr = args;
 }
 
 static
-void   ht_lat(const char* args, const char** unused)
+void   ht_lat(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->latitude = atof(args);
 }
 
 static
-void   ht_long(const char* args, const char** unused)
+void   ht_long(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->longitude = atof(args);
 }
 
 static
-void   ht_alt(const char* args, const char** unused)
+void   ht_alt(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->altitude = atof(args);
 }
 
 static
-void   ht_wpt_e(const char* args, const char** unused)
+void   ht_wpt_e(const char* args, const QXmlStreamAttributes* unused)
 {
   waypt_add(wpt_tmp);
   wpt_tmp = NULL;
 }
 
 static
-void   ht_trk_s(const char* args, const char** unused)
+void   ht_trk_s(const char* args, const QXmlStreamAttributes* unused)
 {
   trk_head = route_head_alloc();
   track_add_head(trk_head);
 }
 
 static
-void   ht_trk_e(const char* args, const char** unused)
+void   ht_trk_e(const char* args, const QXmlStreamAttributes* unused)
 {
 
 }
 
 static
-void   ht_trk_ident(const char* args, const char** unused)
+void   ht_trk_ident(const char* args, const QXmlStreamAttributes* unused)
 {
   trk_head->rte_name = xstrdup(args);
 }
 
 static
-void   ht_trk_pnt_s(const char* args, const char** unused)
+void   ht_trk_pnt_s(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp = waypt_new();
 }
 
 static
-void   ht_trk_pnt_e(const char* args, const char** unused)
+void   ht_trk_pnt_e(const char* args, const QXmlStreamAttributes* unused)
 {
   track_add_wpt(trk_head, wpt_tmp);
 }
 
 static
-void   ht_trk_utc(const char* args, const char** unused)
+void   ht_trk_utc(const char* args, const QXmlStreamAttributes* unused)
 {
   struct tm tm;
   time_t utc;
@@ -263,19 +265,19 @@ void      ht_trk_utc(const char* args, const char** unused)
 }
 
 static
-void   ht_trk_lat(const char* args, const char** unused)
+void   ht_trk_lat(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->latitude = atof(args);
 }
 
 static
-void   ht_trk_long(const char* args, const char** unused)
+void   ht_trk_long(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->longitude = atof(args);
 }
 
 static
-void   ht_trk_alt(const char* args, const char** unused)
+void   ht_trk_alt(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->altitude = atof(args);
 }
index ba38292b06a276a4fbda5f607a616a1e3ed1fbe6..62fbd15e16e8ce06599dc5085260934ab7748229 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdlib.h>
 #include <time.h>
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -103,7 +105,7 @@ static xg_callback  ignr_nb_etapes, ignr_descr;
 static xg_callback     ignr_etape_begin, ignr_etape_end;
 
 static void
-ignr_start(const char* args, const char** attrv)
+ignr_start(const char* args, const QXmlStreamAttributes* attrv)
 {
   ignr_xml_error((track != NULL));
 
@@ -112,13 +114,13 @@ ignr_start(const char* args, const char** attrv)
 }
 
 static void
-ignr_nb_etapes(const char* args, const char** attrv)
+ignr_nb_etapes(const char* args, const QXmlStreamAttributes* attrv)
 {
   xmlpoints = atoi(args);
 }
 
 static void
-ignr_descr(const char* args, const char** attrv)
+ignr_descr(const char* args, const QXmlStreamAttributes* attrv)
 {
   ignr_xml_error((track == NULL));
 
@@ -128,7 +130,7 @@ ignr_descr(const char* args, const char** attrv)
 }
 
 static void
-ignr_etape_begin(const char* args, const char** attrv)
+ignr_etape_begin(const char* args, const QXmlStreamAttributes* attrv)
 {
   ignr_xml_error((wpt != NULL));
 
@@ -136,7 +138,7 @@ ignr_etape_begin(const char* args, const char** attrv)
 }
 
 static void
-ignr_etape_end(const char* args, const char** attrv)
+ignr_etape_end(const char* args, const QXmlStreamAttributes* attrv)
 {
   ignr_xml_error((track == NULL) || (wpt == NULL));
 
@@ -145,7 +147,7 @@ ignr_etape_end(const char* args, const char** attrv)
 }
 
 static void
-ignr_etape_pos(const char* args, const char** attrv)
+ignr_etape_pos(const char* args, const QXmlStreamAttributes* attrv)
 {
   ignr_xml_error((wpt == NULL) || (args == NULL));
 
@@ -155,7 +157,7 @@ ignr_etape_pos(const char* args, const char** attrv)
 }
 
 static void
-ignr_etape_alt(const char* args, const char** attrv)
+ignr_etape_alt(const char* args, const QXmlStreamAttributes* attrv)
 {
   ignr_xml_error((wpt == NULL));
   if (args == NULL) {
index 0e46ff51f05b5531fbf33a80e72d8126e0cb33e6..b320ecfeb55b3d1691dbf1e5d453925ab1e26871 100644 (file)
@@ -20,6 +20,8 @@
 
 */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -31,25 +33,6 @@ static arglist_t ikt_args[] = {
 
 static char* name, *text;
 
-#if ! HAVE_LIBEXPAT
-void
-ikt_rd_init(const char* fname)
-{
-  fatal(MYNAME ": This build excluded \" MYNAME \" support because expat was not installed.\n");
-}
-
-void
-ikt_read(void)
-{
-}
-
-static void
-ikt_object_end(void)
-{
-}
-
-#else
-
 static route_head* track;
 static waypoint* waypt;
 
@@ -97,52 +80,39 @@ ikt_object_end(void)
 }
 
 static void
-iktobj_waypt(const char* args, const char** attrv)
+iktobj_waypt(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
-
-  while (*avp) {
-    if (strcmp(avp[0], "X") == 0) {
-      waypt->longitude = atof(avp[1]);
-    } else if (strcmp(avp[0], "Y") == 0) {
-      waypt->latitude = atof(avp[1]);
-    }
-    avp+=2;
+  if (attrv->hasAttribute("X")) {
+    waypt->longitude = attrv->value("X").toString().toDouble();
+  }
+  if (attrv->hasAttribute("Y")) {
+    waypt->latitude = attrv->value("Y").toString().toDouble();
   }
 }
 
 static void
-iktobj_trkpt(const char* args, const char** attrv)
+iktobj_trkpt(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
-
   waypt = waypt_new();
-  while (*avp) {
-    if (strcmp(avp[0], "X") == 0) {
-      waypt->longitude = atof(avp[1]);
-    } else if (strcmp(avp[0], "Y") == 0) {
-      waypt->latitude = atof(avp[1]);
-    }
-    avp+=2;
-  }
+  iktobj_waypt(args, attrv);
   track_add_wpt(track, waypt);
   waypt = NULL;
 }
 
 static void
-iktobj_name(const char* args, const char** unused)
+iktobj_name(const char* args, const QXmlStreamAttributes* unused)
 {
   name = xstrdup(args);
 }
 
 static void
-iktobj_text(const char* args, const char** unused)
+iktobj_text(const char* args, const QXmlStreamAttributes* unused)
 {
   text = xstrdup(args);
 }
 
 static void
-iktobj_type(const char* args, const char** unused)
+iktobj_type(const char* args, const QXmlStreamAttributes* unused)
 {
   ikt_object_end();
 
@@ -175,8 +145,6 @@ ikt_read(void)
   xml_read();
 }
 
-#endif
-
 static void
 ikt_rd_deinit(void)
 {
index 62c65085eac687ec30c02e3833f9933716e1a848..801825e2c04f4836edf7ae89408bcdbecb8a3911 100644 (file)
@@ -20,6 +20,8 @@
 
 */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 #include "jeeps/gpsmath.h"
@@ -33,20 +35,6 @@ static arglist_t jogmap_args[] = {
 
 #define MYNAME "xol"
 
-#if ! HAVE_LIBEXPAT
-void
-jogmap_rd_init(const char* fname)
-{
-  fatal(MYNAME ": This build excluded \"" MYNAME "\" support because expat was not installed.\n");
-}
-
-void
-jogmap_read(void)
-{
-}
-
-#else
-
 // static xg_callback  jogmap_shape, xol_shape_end;
 // static xg_callback  jogmap_waypt, xol_overlay;
 
@@ -55,28 +43,23 @@ jogmap_read(void)
 
 
 static void
-jogmap_markers(const char* args, const char** attrv)
+jogmap_markers(const char* args, const QXmlStreamAttributes* attrv)
 {
   trk = route_head_alloc();
   track_add_head(trk);
 }
 
 static void
-jogmap_marker(const char* args, const char** attrv)
+jogmap_marker(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
   waypoint* wpt = waypt_new();
 
-  while (*avp) {
-    if (strcmp(avp[0], "lat") == 0) {
-      sscanf(avp[1], "%lf",
-             &wpt->latitude);
-    } else if (strcmp(avp[0], "lng") == 0) {
-      sscanf(avp[1], "%lf",
-             &wpt->longitude);
-    }
+  if (attrv->hasAttribute("lat")) {
+    wpt->latitude = attrv->value("lat").toString().toDouble();
+  }
 
-    avp+=2;
+  if (attrv->hasAttribute("lng")) {
+    wpt->longitude = attrv->value("lng").toString().toDouble();
   }
 
   if (trk) {
@@ -104,8 +87,6 @@ jogmap_read(void)
   xml_read();
 }
 
-#endif
-
 static void
 jogmap_rd_deinit(void)
 {
index 4dd82afd07d14eaa93efe517b2c3e44df073415e..9592e63db06440d858bb59da2b9f69302592bedb 100644 (file)
@@ -22,6 +22,7 @@
  */
 #include <math.h>
 #include <QtCore/QRegExp>
+#include <QtCore/QXmlStreamAttributes>
 
 #ifdef __WIN32__
 # include <windows.h>
@@ -66,9 +67,9 @@ static int wpt_tmp_queued;
 static const char* posnfilename;
 static char* posnfilenametmp;
 
-static gbfile* ofd;
-static QString ostring;
-static gpsbabel::XmlStreamWriter* writer;
+static gbfile* ofd = NULL;
+static QFile oqfile;
+static gpsbabel::XmlStreamWriter* writer = new gpsbabel::XmlStreamWriter(oqfile);
 
 typedef enum  {
   kmlpt_unknown,
@@ -282,13 +283,13 @@ const char* kml_tags_to_ignore[] = {
   NULL,
 };
 
-void wpt_s(const char* args, const char** unused)
+void wpt_s(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp = waypt_new();
   wpt_tmp_queued = 0;
 }
 
-void wpt_e(const char* args, const char** unused)
+void wpt_e(const char* args, const QXmlStreamAttributes* unused)
 {
   if (wpt_tmp_queued) {
     waypt_add(wpt_tmp);
@@ -298,14 +299,14 @@ void wpt_e(const char* args, const char** unused)
   wpt_tmp_queued = 0;
 }
 
-void wpt_name(const char* args, const char** unused)
+void wpt_name(const char* args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     wpt_tmp->shortname = xstrdup(args);
   }
 }
 
-void wpt_desc(const char* args, const char** unused)
+void wpt_desc(const char* args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     char* tmp, *c;
@@ -319,12 +320,12 @@ void wpt_desc(const char* args, const char** unused)
   }
 }
 
-void wpt_time(const char* args, const char** unused)
+void wpt_time(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->SetCreationTime(xml_parse_time(args));
 }
 
-void wpt_coord(const char* args, const char** attrv)
+void wpt_coord(const char* args, const QXmlStreamAttributes* attrv)
 {
   int n = 0;
   double lat, lon, alt;
@@ -340,14 +341,14 @@ void wpt_coord(const char* args, const char** attrv)
   wpt_tmp_queued = 1;
 }
 
-void wpt_icon(const char* args, const char** unused)
+void wpt_icon(const char* args, const QXmlStreamAttributes* unused)
 {
   if (wpt_tmp)  {
     wpt_tmp->icon_descr = args;
   }
 }
 
-void trk_coord(const char* args, const char** attrv)
+void trk_coord(const char* args, const QXmlStreamAttributes* attrv)
 {
   int consumed = 0;
   double lat, lon, alt;
@@ -436,15 +437,10 @@ kml_wr_init(const char* fname)
    * Reduce race conditions with network read link.
    */
   ofd = gbfopen(fname, "w", MYNAME);
+  oqfile.open(ofd->handle.std, QIODevice::WriteOnly);
 
-  writer = new gpsbabel::XmlStreamWriter(ostring);
   writer->setAutoFormattingIndent(2);
-  // Technically, XML (and therefore KML) defaults ot UTF-8, so we should not
-  // have to declare this.  For compatibility with the existing Qt writer,
-  // we do...
-  //writer.setCodec("UTF-8");
-  //writer.writeStartDocument();
-
+  writer->setCodec("UTF-8");
 }
 
 /*
@@ -462,8 +458,8 @@ kml_wr_position_init(const char* fname)
    * 30% of our output file is whitespace.  Since parse time
    * matters in this mode, turn the pretty formatting off.
    */
-  writer = new gpsbabel::XmlStreamWriter(ostring);
   writer->setAutoFormatting(false);
+  writer->setCodec("UTF-8");
 
   max_position_points = atoi(opt_max_position_points);
 }
@@ -472,12 +468,7 @@ static void
 kml_wr_deinit(void)
 {
   writer->writeEndDocument();
-
-  // FIXME: Nuke illegal xml characters.
-  // If we have done things right this shouldn't be necessary.
-  ostring.replace(QRegExp("[\001-\010]"), " ").replace(QRegExp("[\013-\014]"), " ").replace(QRegExp("[\016-\037]"), " ");
-
-  gbfputs(ostring, ofd);
+  oqfile.close();
   gbfclose(ofd);
 
   if (posnfilenametmp) {
@@ -487,9 +478,6 @@ kml_wr_deinit(void)
 #endif
     rename(posnfilenametmp, posnfilename);
   }
-  delete writer;
-  writer = NULL;
-  ostring.clear();
   ofd = NULL;
 }
 
@@ -930,7 +918,7 @@ static void kml_output_point(const waypoint* waypointp, kml_point_type pt_type)
   if (export_points) {
     writer->writeStartElement("Placemark");
     if (atoi(opt_labels)) {
-      writer->writeOptionalTextElement("name", waypointp->shortname);
+      writer->writeOptionalTextElement("name", QString::fromUtf8(waypointp->shortname));
     }
     writer->writeEmptyElement("snippet");
     kml_output_description(waypointp);
@@ -1906,7 +1894,7 @@ void kml_write(void)
 {
   char import_time[100];
   time_t now;
-  const global_trait* traits =  get_traits();
+  const global_trait* traits = get_traits();
 
   // Parse options
   export_lines = (0 == strcmp("1", opt_export_lines));
@@ -1919,7 +1907,7 @@ void kml_write(void)
   trackdirection = (!! strcmp("0", opt_trackdirection));
   line_width = atol(opt_line_width);
 
-  writer->writeProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
+  writer->writeStartDocument();
   // FIXME: This write of a blank line is needed for Qt 4.6 (as on Centos 6.3)
   // to include just enough whitespace between <xml/> and <gpx...> to pass
   // diff -w.  It's here for now to shim compatibility with our zillion
index 3e0ed4b445dfaf565887eaab76e500d763eda132..50c829ec45a2b33f091de945442d1f60ede4ad77 100644 (file)
@@ -26,6 +26,8 @@
  * we don't implement that at this time in GPSBabel.
  */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -333,67 +335,67 @@ lmx_rd_deinit(void)
 
 
 static void
-lmx_lm_start(const char* args, const char** unused)
+lmx_lm_start(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp = waypt_new();
 }
 
 static void
-lmx_lm_end(const char* args, const char** unused)
+lmx_lm_end(const char* args, const QXmlStreamAttributes* unused)
 {
   waypt_add(wpt_tmp);
 }
 
 static void
-lmx_lm_lat(const char* args, const char** unused)
+lmx_lm_lat(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->latitude = atof(args);
 }
 
 static void
-lmx_lm_lon(const char* args, const char** unused)
+lmx_lm_lon(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->longitude = atof(args);
 }
 
 static void
-lmx_lm_alt(const char* args, const char** unused)
+lmx_lm_alt(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->altitude = atof(args);
 }
 
 static void
-lmx_lm_name(const char* args, const char** unused)
+lmx_lm_name(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->shortname = xstrdup(args);
 }
 
 static void
-lmx_lm_desc(const char* args, const char** unused)
+lmx_lm_desc(const char* args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->description = xstrdup(args);
 }
 
 static void
-lmx_lm_mlink_s(const char* args, const char** unused)
+lmx_lm_mlink_s(const char* args, const QXmlStreamAttributes* unused)
 {
   urllink = urllinkt = QString();
 }
 
 static void
-lmx_lm_link(const char* args, const char** unused)
+lmx_lm_link(const char* args, const QXmlStreamAttributes* unused)
 {
   urllink = args;
 }
 
 static void
-lmx_lm_linkt(const char* args, const char** unused)
+lmx_lm_linkt(const char* args, const QXmlStreamAttributes* unused)
 {
   urllinkt = args;
 }
 
 static void
-lmx_lm_mlink_e(const char* args, const char** unused)
+lmx_lm_mlink_e(const char* args, const QXmlStreamAttributes* unused)
 {
   waypt_add_url(wpt_tmp, urllink, urllinkt);
 }
index 65ccdfbcd5955b4c36ec64215a6313a12f4c8872..d68d126596c20807395b4215246cf7c89e727ebe 100644 (file)
@@ -22,6 +22,8 @@
 #include <ctype.h>
 #include <math.h>
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "csv_util.h"
 #include "xmlgeneric.h"
index cd75c613ffa5410177e6500c4bc528da01ddb22f..bdd8862c912c41efdd54564f212a2f1bba9c1d72 100644 (file)
@@ -17,6 +17,7 @@
 
  */
 
+#include <QtCore/QTextCodec>
 
 #include "defs.h"
 #include "filterdefs.h"
@@ -244,6 +245,8 @@ main(int argc, char* argv[])
   signed int wpt_ct_bak, rte_ct_bak, trk_ct_bak;       /* #ifdef UTF8_SUPPORT */
   arg_stack_t* arg_stack = NULL;
 
+  QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
+
   global_opts.objective = wptdata;
   global_opts.masked_objective = NOTHINGMASK;  /* this makes the default mask behaviour slightly different */
   global_opts.charset = NULL;
index fbfa3fa5c70d1aeb7215304fae64182e8a074693..b3249c0de0a041324fc7679b2af2467d375d5031 100644 (file)
@@ -20,6 +20,8 @@
 
 */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "avltree.h"
 #include "xmlgeneric.h"
@@ -35,7 +37,7 @@ static arglist_t osm_args[] = {
 
 #define MYNAME "osm"
 
-static avltree_t* waypoints;   /* AVL tree */
+static QMap<QString, const waypoint*> waypoints;
 
 static avltree_t* keys = NULL;
 static avltree_t* values = NULL;
@@ -493,7 +495,7 @@ osm_strip_html(const char* str)
 
 
 static void
-osm_node_end(const char* args, const char** unused)
+osm_node_end(const char* args, const QXmlStreamAttributes* unused)
 {
   if (wpt) {
     if (wpt->wpt_flags.fmt_use) {
@@ -507,49 +509,53 @@ osm_node_end(const char* args, const char** unused)
 
 
 static void
-osm_node(const char* args, const char** attrv)
+osm_node(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
-
   wpt = waypt_new();
 
-  while (*avp) {
-    if (strcmp(avp[0], "id") == 0) {
-      xasprintf(&wpt->description, "osm-id %s", avp[1]);
-      if (! avltree_insert(waypoints, avp[1], (void*)wpt)) {
-        warning(MYNAME ": Duplicate osm-id %s!\n", avp[1]);
-      } else {
-        wpt->wpt_flags.fmt_use = 1;
-      }
-    } else if (strcmp(avp[0], "user") == 0) ;
-    else if (strcmp(avp[0], "lat") == 0) {
-      wpt->latitude = atof(avp[1]);
-    } else if (strcmp(avp[0], "lon") == 0) {
-      wpt->longitude = atof(avp[1]);
-    } else if (strcmp(avp[0], "timestamp") == 0) {
-      wpt->creation_time = xml_parse_time(avp[1]);
+  if (attrv->hasAttribute("id")) {
+    QString atstr = attrv->value("id").toString();
+
+    xasprintf(&wpt->description, "osm-id %s", CSTR(atstr));
+    if (waypoints.contains(atstr)) {
+      warning(MYNAME ": Duplicate osm-id %s!\n", CSTR(atstr));
+    } else {
+      waypoints.insert(atstr, wpt);
+      wpt->wpt_flags.fmt_use = 1;
     }
+  }
+
+  // if (attrv->hasAttribute("user")) ; // ignored
 
-    avp += 2;
+  if (attrv->hasAttribute("lat")) {
+    wpt->latitude = attrv->value("lat").toString().toDouble();
+  }
+  if (attrv->hasAttribute("lon")) {
+    wpt->longitude = attrv->value("lon").toString().toDouble();
+  }
+
+  if (attrv->hasAttribute("timestamp")) {
+    QByteArray tsutf8 = attrv->value("timestamp").toString().toUtf8();
+    wpt->creation_time = xml_parse_time(tsutf8.constData());
   }
 }
 
 
 static void
-osm_node_tag(const char* args, const char** attrv)
+osm_node_tag(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
+  QByteArray qkey, qvalue;
   const char* key = "", *value = "";
   char* str;
   signed char ikey;
 
-  while (*avp) {
-    if (strcmp(avp[0], "k") == 0) {
-      key = avp[1];
-    } else if (strcmp(avp[0], "v") == 0) {
-      value = avp[1];
-    }
-    avp+=2;
+  if (attrv->hasAttribute("k")) {
+    qkey = attrv->value("k").toString().toUtf8();
+    key = qkey.constData();
+  }
+  if (attrv->hasAttribute("v")) {
+    qvalue = attrv->value("v").toString().toUtf8();
+    value = qvalue.constData();
   }
 
   str = osm_strip_html(value);
@@ -601,53 +607,48 @@ osm_node_tag(const char* args, const char** attrv)
 
 
 static void
-osm_way(const char* args, const char** attrv)
+osm_way(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
-
   rte = route_head_alloc();
 
-  while (*avp) {
-    if (strcmp(avp[0], "id") == 0) {
-      xasprintf(&rte->rte_desc, "osm-id %s", avp[1]);
-    }
-    avp += 2;
+  if (attrv->hasAttribute("id")) {
+      xasprintf(&rte->rte_desc, "osm-id %s",
+                attrv->value("id").toString().toUtf8().constData());
   }
 }
 
 static void
-osm_way_nd(const char* args, const char** attrv)
+osm_way_nd(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
-
-  while (*avp) {
-    if (strcmp(avp[0], "ref") == 0) {
-      waypoint* tmp;
-      if (avltree_find(waypoints, avp[1], (const void**)&tmp)) {
-        tmp = waypt_dupe(tmp);
-        route_add_wpt(rte, tmp);
-      } else {
-        warning(MYNAME ": Way reference id \"%s\" wasn't listed under nodes!\n", avp[1]);
-      }
+  if (attrv->hasAttribute("ref")) {
+    QString atstr = attrv->value("ref").toString();
+    waypoint* tmp;
+    const waypoint* ctmp;
+
+    if (waypoints.contains(atstr)) {
+      ctmp = waypoints.value(atstr);
+      tmp = waypt_dupe(ctmp);
+      route_add_wpt(rte, tmp);
+    } else {
+      warning(MYNAME ": Way reference id \"%s\" wasn't listed under nodes!\n", CSTR(atstr));
     }
-    avp += 2;
   }
 }
 
 static void
-osm_way_tag(const char* args, const char** attrv)
+osm_way_tag(const char* args, const QXmlStreamAttributes* attrv)
 {
-  const char** avp = &attrv[0];
+  QByteArray qkey, qvalue;
   const char* key = "", *value = "";
   char* str;
 
-  while (*avp) {
-    if (strcmp(avp[0], "k") == 0) {
-      key = avp[1];
-    } else if (strcmp(avp[0], "v") == 0) {
-      value = avp[1];
-    }
-    avp += 2;
+  if (attrv->hasAttribute("k")) {
+    qkey = attrv->value("k").toString().toUtf8();
+    key = qkey.constData();
+  }
+  if (attrv->hasAttribute("v")) {
+    qvalue = attrv->value("v").toString().toUtf8();
+    value = qvalue.constData();
   }
 
   str = osm_strip_html(value);
@@ -667,7 +668,7 @@ osm_way_tag(const char* args, const char** attrv)
 }
 
 static void
-osm_way_end(const char* args, const char** unused)
+osm_way_end(const char* args, const QXmlStreamAttributes* unused)
 {
   if (rte) {
     route_add_head(rte);
@@ -683,7 +684,7 @@ osm_rd_init(const char* fname)
   wpt_loaded = 0;
   rte_loaded = 0;
 
-  waypoints = avltree_init(0, MYNAME);
+  waypoints.clear();
   if (! keys) {
     osm_features_init();
   }
@@ -703,7 +704,7 @@ static void
 osm_rd_deinit(void)
 {
   xml_deinit();
-  avltree_done(waypoints);
+  waypoints.clear();
 }
 
 /*******************************************************************************/
@@ -785,83 +786,92 @@ osm_release_ids(const waypoint* wpt)
   }
 }
 
+static QString
+osm_name_from_wpt(const waypoint* wpt)
+{
+  QString name = QString("%1\01%2\01%3")
+      .arg((wpt->shortname) ? wpt->shortname : "")
+      .arg(wpt->latitude)
+      .arg(wpt->longitude);
+  return name;
+}
+
 static void
 osm_waypt_disp(const waypoint* wpt)
 {
-  char* buff;
+  QString name = osm_name_from_wpt(wpt);
 
-  xasprintf(&buff, "%s\01%f\01%f", (wpt->shortname) ? wpt->shortname : "",
-            wpt->latitude, wpt->longitude);
-
-  if (avltree_insert(waypoints, buff, (const void*) wpt)) {
-    int* id;
+  if (waypoints.contains(name)) {
+    return;
+  }
 
-    id = (int*) xmalloc(sizeof(*id));
-    *id = --node_id;
-    ((waypoint*)(wpt))->extra_data = id;
+  waypoints.insert(name, wpt);
 
-    gbfprintf(fout, "  <node id='%d' visible='true' lat='%0.7f' lon='%0.7f'", *id, wpt->latitude, wpt->longitude);
-    if (wpt->creation_time) {
-      QString time_string = wpt->CreationTimeXML();
-      gbfprintf(fout, " timestamp='%s'", qPrintable(time_string));
-    }
-    gbfprintf(fout, ">\n");
+  int* id;
 
-    if (wpt->hdop) {
-      gbfprintf(fout, "    <tag k='gps:hdop' v='%f' />\n", wpt->hdop);
-    }
-    if (wpt->vdop) {
-      gbfprintf(fout, "    <tag k='gps:vdop' v='%f' />\n", wpt->vdop);
-    }
-    if (wpt->pdop) {
-      gbfprintf(fout, "    <tag k='gps:pdop' v='%f' />\n", wpt->pdop);
-    }
-    if (wpt->sat > 0) {
-      gbfprintf(fout, "    <tag k='gps:sat' v='%d' />\n", wpt->sat);
-    }
+  id = (int*) xmalloc(sizeof(*id));
+  *id = --node_id;
+  ((waypoint*)(wpt))->extra_data = id;
 
-    switch (wpt->fix) {
-    case fix_2d:
-      gbfprintf(fout, "    <tag k='gps:fix' v='2d' />\n");
-      break;
-    case fix_3d:
-      gbfprintf(fout, "    <tag k='gps:fix' v='3d' />\n");
-      break;
-    case fix_dgps:
-      gbfprintf(fout, "    <tag k='gps:fix' v='dgps' />\n");
-      break;
-    case fix_pps:
-      gbfprintf(fout, "    <tag k='gps:fix' v='pps' />\n");
-      break;
-    case fix_none:
-      gbfprintf(fout, "    <tag k='gps:fix' v='none' />\n");
-      break;
-    case fix_unknown:
-    default:
-      break;
-    }
+  gbfprintf(fout, "  <node id='%d' visible='true' lat='%0.7f' lon='%0.7f'", *id, wpt->latitude, wpt->longitude);
+  if (wpt->creation_time) {
+    QString time_string = wpt->CreationTimeXML();
+    gbfprintf(fout, " timestamp='%s'", qPrintable(time_string));
+  }
+  gbfprintf(fout, ">\n");
 
-    if (strlen(created_by) !=0) {
-      gbfprintf(fout, "    <tag k='created_by' v='%s",created_by);
-      if (gpsbabel_time != 0)
-        if (strcmp("GPSBabel",created_by)==0) {
-          gbfprintf(fout, "-%s", gpsbabel_version);
-        }
-      gbfprintf(fout, "'/>\n");
-    }
+  if (wpt->hdop) {
+    gbfprintf(fout, "    <tag k='gps:hdop' v='%f' />\n", wpt->hdop);
+  }
+  if (wpt->vdop) {
+    gbfprintf(fout, "    <tag k='gps:vdop' v='%f' />\n", wpt->vdop);
+  }
+  if (wpt->pdop) {
+    gbfprintf(fout, "    <tag k='gps:pdop' v='%f' />\n", wpt->pdop);
+  }
+  if (wpt->sat > 0) {
+    gbfprintf(fout, "    <tag k='gps:sat' v='%d' />\n", wpt->sat);
+  }
 
-    osm_write_tag("name", wpt->shortname);
-    osm_write_tag("note", (wpt->notes) ? wpt->notes : wpt->description);
-    if (!wpt->icon_descr.isNull()) {
-      osm_disp_feature(wpt);
-    }
+  switch (wpt->fix) {
+  case fix_2d:
+    gbfprintf(fout, "    <tag k='gps:fix' v='2d' />\n");
+    break;
+  case fix_3d:
+    gbfprintf(fout, "    <tag k='gps:fix' v='3d' />\n");
+    break;
+  case fix_dgps:
+    gbfprintf(fout, "    <tag k='gps:fix' v='dgps' />\n");
+    break;
+  case fix_pps:
+    gbfprintf(fout, "    <tag k='gps:fix' v='pps' />\n");
+    break;
+  case fix_none:
+    gbfprintf(fout, "    <tag k='gps:fix' v='none' />\n");
+    break;
+  case fix_unknown:
+  default:
+    break;
+  }
 
-    osm_write_opt_tag(opt_tagnd);
+  if (strlen(created_by) !=0) {
+    gbfprintf(fout, "    <tag k='created_by' v='%s",created_by);
+    if (gpsbabel_time != 0)
+      if (strcmp("GPSBabel",created_by)==0) {
+        gbfprintf(fout, "-%s", gpsbabel_version);
+      }
+    gbfprintf(fout, "'/>\n");
+  }
 
-    gbfprintf(fout, "  </node>\n");
+  osm_write_tag("name", wpt->shortname);
+  osm_write_tag("note", (wpt->notes) ? wpt->notes : wpt->description);
+  if (!wpt->icon_descr.isNull()) {
+    osm_disp_feature(wpt);
   }
 
-  xfree(buff);
+  osm_write_opt_tag(opt_tagnd);
+
+  gbfprintf(fout, "  </node>\n");
 }
 
 static void
@@ -879,22 +889,18 @@ osm_rte_disp_head(const route_head* rte)
 static void
 osm_rtept_disp(const waypoint* wpt_ref)
 {
-  char* buff;
-  waypoint* wpt;
+  QString name = osm_name_from_wpt(wpt_ref);
+  const waypoint* wpt;
 
   if (skip_rte) {
     return;
   }
 
-  xasprintf(&buff, "%s\01%f\01%f", (wpt_ref->shortname) ? wpt_ref->shortname : "",
-            wpt_ref->latitude, wpt_ref->longitude);
-
-  if (avltree_find(waypoints, buff, (const void**) &wpt)) {
+  if (waypoints.contains(name)) {
+    wpt = waypoints.value(name);
     int* id = (int*) wpt->extra_data;
     gbfprintf(fout, "    <nd ref='%d'/>\n", *id);
   }
-
-  xfree(buff);
 }
 
 static void
@@ -931,7 +937,7 @@ osm_wr_init(const char* fname)
   fout = gbfopen(fname, "w", MYNAME);
 
   osm_init_icons();
-  waypoints = avltree_init(0, MYNAME);
+  waypoints.clear();
   node_id = 0;
 }
 
@@ -964,7 +970,7 @@ osm_wr_deinit(void)
   route_disp_all(NULL, NULL, osm_release_ids);
   track_disp_all(NULL, NULL, osm_release_ids);
 
-  avltree_done(waypoints);
+  waypoints.clear();
 }
 
 static void
index c25b1c4c0dddc7cb71ef4bd90ef16ca2690f3f54..c11c286ab004a0a89cbaf988b65cfa6a25b5e117 100644 (file)
@@ -19,6 +19,8 @@
 
  */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -83,7 +85,7 @@ wr_init(const char *fname)
   fatal("Writing file of type %s is not supported\n", MYNAME);
 }
 
-void   wpt_s(const char *args, const char **unused)
+void   wpt_s(const char *args, const QXmlStreamAttributes* unused)
 {
   if (isFirst == 1) {
     wpt_from = waypt_new();
@@ -94,7 +96,7 @@ void  wpt_s(const char *args, const char **unused)
   wpt_to = waypt_new();
 }
 
-void   wpt_e(const char *args, const char **unused)
+void   wpt_e(const char *args, const QXmlStreamAttributes* unused)
 {
   if (isFirst == 1) {
     route_add_wpt(route, wpt_from);
@@ -111,66 +113,63 @@ void      wpt_e(const char *args, const char **unused)
   wpt_to = NULL;
 }
 
-void   wpt_from_lat(const char *args, const char **unused)
+void   wpt_from_lat(const char *args, const QXmlStreamAttributes* unused)
 {
   if (wpt_from != NULL) {
     wpt_from->latitude = atof(args);
   }
 }
 
-void   wpt_from_lon(const char *args, const char **unused)
+void   wpt_from_lon(const char *args, const QXmlStreamAttributes* unused)
 {
   if (wpt_from != NULL) {
     wpt_from->longitude = atof(args);
   }
 }
 
-void   wpt_from_name(const char *args, const char **unused)
+void   wpt_from_name(const char *args, const QXmlStreamAttributes* unused)
 {
   if (wpt_from != NULL) {
     wpt_from->shortname = xstrappend(wpt_from->shortname, args);
   }
 }
 
-void   wpt_from_elev(const char *args, const char **unused)
+void   wpt_from_elev(const char *args, const QXmlStreamAttributes* unused)
 {
   if (wpt_from != NULL) {
     wpt_from->altitude = FEET_TO_METERS(atof(args));
   }
 }
 
-void   wpt_to_lat(const char *args, const char **unused)
+void   wpt_to_lat(const char *args, const QXmlStreamAttributes* unused)
 {
   wpt_to->latitude = atof(args);
 }
 
-void   wpt_to_lon(const char *args, const char **unused)
+void   wpt_to_lon(const char *args, const QXmlStreamAttributes* unused)
 {
   wpt_to->longitude = atof(args);
 }
 
-void   wpt_to_name(const char *args, const char **unused)
+void   wpt_to_name(const char *args, const QXmlStreamAttributes* unused)
 {
   wpt_to->shortname = xstrappend(wpt_to->shortname, args);
 }
 
-void   wpt_to_elev(const char *args, const char **unused)
+void   wpt_to_elev(const char *args, const QXmlStreamAttributes* unused)
 {
   dest_altitude = FEET_TO_METERS(atof(args));
 }
 
-void   wpt_altitude(const char *args, const char **attrv)
+void   wpt_altitude(const char *args, const QXmlStreamAttributes* attrv)
 {
   int isFeet = 0;
-  const char **avp = &attrv[0];
-  while (*avp) {
-    if (0 == strcmp(avp[0], "Value")) {
-      wpt_to->altitude = atof(avp[1]);
-    }
-    if (0 == strcmp(avp[0], "Unit")) {
-      isFeet = strcmp(avp[1], "ft") == 0 ? 1 : 0;
-    }
-    avp += 2;
+
+  if (attrv->hasAttribute("Value")) {
+    wpt_to->altitude = attrv->value("Value").toString().toDouble();
+  }
+  if (attrv->hasAttribute("Unit")) {
+    isFeet = (attrv->value("Unit") == "ft");
   }
   if (isFeet) {
     wpt_to->altitude = FEET_TO_METERS(wpt_to->altitude);
index 2a3d98106092a31ac1a125a4752732192a9ac18e..61c6afadec315f97bc0f14dec1e707c7ed959b87 100644 (file)
@@ -52,7 +52,7 @@
   </rte>
   <rte>
     <name>step004</name>
-    <desc>Slight right onto Pl. LapÃ\83¨rouse</desc>
+    <desc>Slight right onto Pl. Lapèrouse</desc>
     <rtept lat="43.925620000" lon="2.145510000">
       <name>RPT013</name>
     </rtept>
@@ -77,7 +77,7 @@
   </rte>
   <rte>
     <name>step005</name>
-    <desc>Slight left to stay on Pl. LapÃ\83¨rouse</desc>
+    <desc>Slight left to stay on Pl. Lapèrouse</desc>
     <rtept lat="43.925830000" lon="2.145030000">
       <name>RPT020</name>
     </rtept>
   </rte>
   <rte>
     <name>step006</name>
-    <desc>Continue onto Av. GÃ\83©nÃ\83©ral de Gaulle</desc>
+    <desc>Continue onto Av. Général de Gaulle</desc>
     <rtept lat="43.924200000" lon="2.144330000">
       <name>RPT042</name>
     </rtept>
   </rte>
   <rte>
     <name>step007</name>
-    <desc>At the roundabout, take the 1st exit onto Av. MarÃ\83©chal Joffre</desc>
+    <desc>At the roundabout, take the 1st exit onto Av. Maréchal Joffre</desc>
     <rtept lat="43.922490000" lon="2.142280000">
       <name>RPT048</name>
     </rtept>
   </rte>
   <rte>
     <name>step009</name>
-    <desc>Turn right onto Av. FranÃ\83§ois Verdier/D988Continue to follow D988</desc>
+    <desc>Turn right onto Av. François Verdier/D988Continue to follow D988</desc>
     <rtept lat="43.919590000" lon="2.135000000">
       <name>RPT089</name>
     </rtept>
   </rte>
   <rte>
     <name>step013</name>
-    <desc>Keep left at the fork, follow signs for A61/PÃ\83©riphÃ\83©rique IntÃ\83©rieur/La Roseraie/Toulouse-Centre/Montpellier/Barcelone/Foix and merge onto A61Partial toll road</desc>
+    <desc>Keep left at the fork, follow signs for A61/Périphérique Intérieur/La Roseraie/Toulouse-Centre/Montpellier/Barcelone/Foix and merge onto A61Partial toll road</desc>
     <rtept lat="43.638120000" lon="1.483170000">
       <name>RPT1595</name>
     </rtept>
   </rte>
   <rte>
     <name>step017</name>
-    <desc>Continue onto Av. LÃ\83©on Blum</desc>
+    <desc>Continue onto Av. Léon Blum</desc>
     <rtept lat="43.614770000" lon="1.463970000">
       <name>RPT1853</name>
     </rtept>
   </rte>
   <rte>
     <name>step021</name>
-    <desc>Continue onto AllÃ\83©e Jean JaurÃ\83¨s/AllÃ\83©es Jean-JaurÃ\83¨s</desc>
+    <desc>Continue onto Allée Jean Jaurès/Allées Jean-Jaurès</desc>
     <rtept lat="43.609300000" lon="1.453880000">
       <name>RPT1946</name>
     </rtept>
   </rte>
   <rte>
     <name>step022</name>
-    <desc>Slight left onto AllÃ\83©e PrÃ\83©sident Roosevelt</desc>
+    <desc>Slight left onto Allée Président Roosevelt</desc>
     <rtept lat="43.605870000" lon="1.448620000">
       <name>RPT1964</name>
     </rtept>
   </rte>
   <rte>
     <name>step023</name>
-    <desc>Turn right onto Pl. du PrÃ\83©sident Thomas Wilson</desc>
+    <desc>Turn right onto Pl. du Président Thomas Wilson</desc>
     <rtept lat="43.605190000" lon="1.447670000">
       <name>RPT1970</name>
     </rtept>
index 4723444ecf5a732e5473af2c3cec3e6b816203ce..c9dc317eac79d89018b3ef1634cb594e731e3ab0 100644 (file)
@@ -1,11 +1,11 @@
-41.87895, -87.63665, S Upper Wacker Dr
+41.87895, -87.63665, Head  north from S Upper Wacker Dr
 41.87924, -87.63666, \00001
 41.87937, -87.63666, \00002
 41.87952, -87.63667, \00003
 41.88063, -87.63672, \00004
 41.88126, -87.63673, \00005
 41.88194, -87.63676, \00006
-41.88194, -87.63676, N Upper Wacker Dr
+41.88194, -87.63676, Continue on N Upper Wacker Dr
 41.88206, -87.63676, \00008
 41.88257, -87.63678, \00009
 41.88301, -87.63679, \0000a
@@ -16,7 +16,7 @@
 41.88519, -87.63686, \0000f
 41.88542, -87.63686, \00010
 41.88574, -87.63682, \00011
-41.88574, -87.63682, W Upper Wacker Dr
+41.88574, -87.63682, Bear right at W Upper Wacker Dr
 41.88583, -87.63678, \00013
 41.88595, -87.63666, \00014
 41.88677, -87.63538, \00015
 41.88677, -87.63477, \00017
 41.88677, -87.63394, \00018
 41.88677, -87.63249, \00019
-41.88677, -87.63249, N La Salle St
+41.88677, -87.63249, Turn left at N La Salle St
 41.88696, -87.63248, \0001b
 41.88710, -87.63248, \0001c
 41.88780, -87.63248, \0001d
-41.88780, -87.63248, N La Salle Blvd
+41.88780, -87.63248, Continue on N La Salle Blvd
 41.88919, -87.63254, \0001f
 41.89000, -87.63254, \00020
 41.89078, -87.63257, \00021
 41.90772, -87.63305, \00031
 41.90917, -87.63309, \00032
 41.91117, -87.63313, \00033
-41.91117, -87.63313, N La Salle Dr
+41.91117, -87.63313, Continue on N La Salle Dr
 41.91265, -87.63317, \00035
 41.91289, -87.63316, \00036
-41.91289, -87.63316, W Eugenie St
+41.91289, -87.63316, Bear right at W Eugenie St
 41.91299, -87.63310, \00038
 41.91307, -87.63301, \00039
 41.91314, -87.63284, \0003a
-41.91314, -87.63284, N Clark St
+41.91314, -87.63284, Turn left at N Clark St
 41.91380, -87.63324, \0003c
 41.91485, -87.63388, \0003d
 41.91560, -87.63433, \0003e
 41.94558, -87.65510, \0006a
 41.94654, -87.65592, \0006b
 41.94718, -87.65639, \0006c
-41.94718, -87.65639, W Addison St
+41.94718, -87.65639, Turn right at W Addison St
 41.94719, -87.65553, \0006e
index cdb65735c0121bc32dd67dcf2237559607f1c02e..1c5d00261ca84fa9a709a5fafdb2bba6f535f0fa 100644 (file)
@@ -23,6 +23,8 @@
 
 */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -44,20 +46,6 @@ static arglist_t tef_xml_args[] = {
 
 #define MYNAME "TourExchangeFormat"
 
-#if ! HAVE_LIBEXPAT
-void
-tef_xml_rd_init(const char *fname)
-{
-  fatal(MYNAME ": This build excluded TEF support because expat was not installed.\n");
-}
-
-void
-tef_xml_read(void)
-{
-}
-
-#else
-
 static char *
 trimmed_strdup(const char *str)
 {
@@ -95,21 +83,20 @@ xg_tag_mapping tef_xml_map[] = {
  */
 
 void
-tef_start(const char *args, const char **attrv)
+tef_start(const char *args, const QXmlStreamAttributes* attrv)
 {
-  int valid = 0;
-  const char **avp = &attrv[0];
+  bool valid = false;
 
-  while (*avp) {
-    if (0 == case_ignore_strcmp(avp[0], "Comment")) {
-      if (0 == case_ignore_strcmp(avp[1], "TourExchangeFormat")) {
-        valid = 1;
+  foreach (QXmlStreamAttribute attr, *attrv) {
+    if (attr.name().compare("Comment", Qt::CaseInsensitive) == 0) {
+      if (attr.value().compare("TourExchangeFormat", Qt::CaseInsensitive) == 0) {
+        valid = true;
       }
-    } else if (0 == case_ignore_strcmp(avp[0], "Version")) {
-      version = atof(avp[1]);
+    } else if (attr.name().compare("Version", Qt::CaseInsensitive) == 0) {
+      version = attr.value().toString().toDouble();
     }
-    avp+=2;
   }
+
   if (!valid) {
     fatal(MYNAME ": Error in source file.\n");
   }
@@ -120,32 +107,24 @@ tef_start(const char *args, const char **attrv)
  */
 
 static void
-tef_header(const char *args, const char **attrv)
+tef_header(const char *args, const QXmlStreamAttributes* attrv)
 {
-  const char **avp = &attrv[0];
-
   route = route_head_alloc();
-  while (*avp) {
-    if (case_ignore_strcmp(avp[0], "Name") == 0) {
-      route->rte_name = trimmed_strdup(avp[1]);
-    } else if (case_ignore_strcmp(avp[0], "Software") == 0) {
-      route->rte_desc = trimmed_strdup(avp[1]);
+  foreach (QXmlStreamAttribute attr, *attrv) {
+    if (attr.name().compare("Name", Qt::CaseInsensitive) == 0) {
+      route->rte_name = trimmed_strdup(attr.value().toString().toUtf8().constData());
+    } else if (attr.name().compare("Software", Qt::CaseInsensitive) == 0) {
+      route->rte_desc = trimmed_strdup(attr.value().toString().toUtf8().constData());
     }
-    avp+=2;
   }
   route_add_head(route);
 }
 
 static void
-tef_list_start(const char *args, const char **attrv)
+tef_list_start(const char *args, const QXmlStreamAttributes* attrv)
 {
-  const char **avp = &attrv[0];
-
-  while (*avp) {
-    if (strcmp(avp[0], "ItemCount") == 0) {
-      sscanf(avp[1], "%d", &item_count);
-    }
-    avp+=2;
+  if (attrv->hasAttribute("ItemCount")) {
+    item_count = attrv->value("ItemCount").toString().toUInt();
   }
 }
 
@@ -229,13 +208,13 @@ waypoint_final()
 }
 
 static void
-tef_item_end(const char *args, const char **unused)
+tef_item_end(const char *args, const QXmlStreamAttributes* unused)
 {
   waypoint_final();
 }
 
 static void
-tef_list_end(const char *args, const char **unused)
+tef_list_end(const char *args, const QXmlStreamAttributes* unused)
 {
   waypoint_final();
   if (waypoints != item_count)
@@ -244,10 +223,8 @@ tef_list_end(const char *args, const char **unused)
 }
 
 static void
-tef_item_start(const char *args, const char **attrv)
+tef_item_start(const char *args, const QXmlStreamAttributes* attrv)
 {
-  const char **avp = &attrv[0];
-
   waypoints++;
 
   wpt_tmp = waypt_new();
@@ -255,59 +232,57 @@ tef_item_start(const char *args, const char **attrv)
     wpt_tmp->wpt_flags.fmt_use ++;
   }
 
-  while (*avp) {
-    if (0 == case_ignore_strcmp(avp[0], "SegDescription")) {
-      wpt_tmp->shortname = trimmed_strdup(avp[1]);
-    } else if (0 == case_ignore_strcmp(avp[0], "PointDescription")) {
-      wpt_tmp->description = trimmed_strdup(avp[1]);
-    } else if ((0 == case_ignore_strcmp(avp[0], "ViaStation")) &&
-               (0 == case_ignore_strcmp(avp[1], "true"))) {
-      wpt_tmp->wpt_flags.fmt_use  = 1;  /* only a flag */
-    }
+  foreach (QXmlStreamAttribute attr, *attrv) {
+    QString attrstr = attr.value().toString();
+    QByteArray attrtext = attrstr.toUtf8();
+
+    if (attr.name().compare("SegDescription", Qt::CaseInsensitive) == 0) {
+      wpt_tmp->shortname = trimmed_strdup(attrtext.constData());
+    } else if (attr.name().compare("PointDescription", Qt::CaseInsensitive) == 0) {
+      wpt_tmp->description = trimmed_strdup(attrtext.constData());
+    } else if (attr.name().compare("ViaStation", Qt::CaseInsensitive) == 0 &&
+               attr.value().compare("true", Qt::CaseInsensitive) == 0) {
+      wpt_tmp->wpt_flags.fmt_use = 1;  /* only a flag */
 
     /* new in TEF V2 */
-    else if (0 == case_ignore_strcmp(avp[0], "Instruction")) {
-      wpt_tmp->description = trimmed_strdup(avp[1]);
-    } else if (0 == case_ignore_strcmp(avp[0], "Altitude")) {
-      wpt_tmp->altitude = atof(avp[1]);
-    } else if (0 == case_ignore_strcmp(avp[0], "TimeStamp")) {
+    } else if (attr.name().compare("Instruction", Qt::CaseInsensitive) == 0) {
+      wpt_tmp->description = trimmed_strdup(attrtext.constData());
+    } else if (attr.name().compare("Altitude", Qt::CaseInsensitive) == 0) {
+      wpt_tmp->altitude = attrstr.toDouble();
+    } else if (attr.name().compare("TimeStamp", Qt::CaseInsensitive) == 0) {
       /* nothing for the moment */
     }
+  }
+}
+
+static double
+tef_read_comma_float(const QStringRef& value)
+{
+  QString svalue = value.toString();
+  int cidx;
 
-    avp+=2;
+  cidx = svalue.indexOf(',');
+  if (cidx == -1) {
+    return svalue.toDouble();
   }
+
+  QString fixed = svalue.replace(cidx, 1, '.');
+  return fixed.toDouble();
 }
 
 static void
-tef_point(const char *args, const char **attrv)
+tef_point(const char *args, const QXmlStreamAttributes* attrv)
 {
-  const char **avp = &attrv[0];
-  char *comma;
-
   if (!wpt_tmp) {
     return;
   }
 
-  // FIXME: this code should really not be writing into the arg list.
-  while (*avp) {
-    if (strcmp(avp[0], "y") == 0) {
-      char *tbuf = xstrdup(avp[1]);
-      comma = strstr(tbuf, ",");
-      if (comma) {
-        *comma='.';
-      }
-      sscanf(tbuf, "%lf", &wpt_tmp->latitude);
-      xfree(tbuf);
-    } else if (strcmp(avp[0], "x") == 0) {
-      char *tbuf = xstrdup(avp[1]);
-      comma = strstr(tbuf, ",");
-      if (comma) {
-        *comma='.';
-      }
-      sscanf(tbuf, "%lf", &wpt_tmp->longitude);
-      xfree(tbuf);
-    }
-    avp+=2;
+  if (attrv->hasAttribute("y")) {
+    wpt_tmp->latitude = tef_read_comma_float(attrv->value("y"));
+  }
+
+  if (attrv->hasAttribute("x")) {
+    wpt_tmp->longitude = tef_read_comma_float(attrv->value("x"));
   }
 }
 
@@ -328,8 +303,6 @@ tef_xml_read(void)
   xml_read();
 }
 
-#endif
-
 static void
 tef_xml_rd_deinit(void)
 {
index bbc62e389cdd3f761003c61147c781e3c7692781..bfcf147a71e9265c9a80cab1dfece55f11337c82 100644 (file)
@@ -40,6 +40,8 @@
 #include <ctype.h>
 #include <math.h>
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "filterdefs.h"
 #include "strptime.h"
index d908e8c910ed401cfb40a6eb5b664175f32d10b3..1ee7969ef14e60ee565b4f673233a20d63d188cb 100644 (file)
@@ -1561,10 +1561,7 @@ char *
 strip_html(const utf_string *in)
 {
   char* outstring, *out;
-  // If toUtf8() is used here, we double encode in the OSM test case.
-  // this may be a bug here or elsewhere.
-  char* incopy, *instr;
-  incopy = instr = xstrdup(in->utfstring.toLatin1().data());
+  char* instr = xstrdup(CSTR(in->utfstring));
   char tag[8];
   unsigned short int taglen = 0;
 
@@ -1574,8 +1571,7 @@ strip_html(const utf_string *in)
   /*
    * We only shorten, so just dupe the input buf for space.
    */
-
-  outstring = out = xstrdup(in->utfstring.toUtf8().data());
+   outstring = out = xstrdup(CSTR(in->utfstring));
 
   tag[0] = 0;
   while (*instr) {
@@ -1638,9 +1634,6 @@ strip_html(const utf_string *in)
     instr++;
   }
   *out++ = 0;
-  if (incopy) {
-    xfree(incopy);
-  }
   return (outstring);
 }
 
index 5eab13051e2c7b127cf49142cb65c32703dab1cc..9e9330578f26b4d1d142730c52883a70e46e4cd3 100644 (file)
@@ -16,6 +16,9 @@
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
 
  */
+
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -111,7 +114,7 @@ static double       ap_lat          =0.0;
 static double  ap_lon          =0.0;
 
 /*     Start of AP block */
-void wfff_s(const char *args, const char **unused)
+void wfff_s(const char *args, const QXmlStreamAttributes* unused)
 {
   xfreez(ap_mac);
   xfreez(ap_ssid);
@@ -128,84 +131,84 @@ void wfff_s(const char *args, const char **unused)
   ap_lon=0.0;
 }
 
-void wfff_mac(const char *args, const char **unused)
+void wfff_mac(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_mac = xstrdup(args);
   }
 }
 
-void wfff_ssid(const char *args, const char **unused)
+void wfff_ssid(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_ssid = xstrdup(args);
   }
 }
 
-void wfff_type(const char *args, const char **unused)
+void wfff_type(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_type = xstrdup(args);
   }
 }
 
-void wfff_mnrssi(const char *args, const char **unused)
+void wfff_mnrssi(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_mnrssi = atof(args);
   }
 }
 
-void wfff_mxrssi(const char *args, const char **unused)
+void wfff_mxrssi(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_mxrssi = atof(args);
   }
 }
 
-void wfff_chan(const char *args, const char **unused)
+void wfff_chan(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_chan = atoi(args);
   }
 }
 
-void wfff_first(const char *args, const char **unused)
+void wfff_first(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_first = xml_parse_time(args);
   }
 }
 
-void wfff_last(const char *args, const char **unused)
+void wfff_last(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_last = xstrdup(args);
   }
 }
 
-void wfff_wep(const char *args, const char **unused)
+void wfff_wep(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_wep = xstrdup(args);
   }
 }
 
-void wfff_hdop(const char *args, const char **unused)
+void wfff_hdop(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_hdop = atof(args);
   }
 }
 
-void wfff_lat(const char *args, const char **unused)
+void wfff_lat(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_lat = atof(args);
   }
 }
 
-void wfff_lon(const char *args, const char **unused)
+void wfff_lon(const char *args, const QXmlStreamAttributes* unused)
 {
   if (args) {
     ap_lon = atof(args);
@@ -215,7 +218,7 @@ void wfff_lon(const char *args, const char **unused)
 /*     End of AP Block, set waypoint and add */
 static long tosscount=0;
 
-void wfff_e(const char *args, const char **unused)
+void wfff_e(const char *args, const QXmlStreamAttributes* unused)
 {
   waypoint*    wpt_tmp         =0;
   char         desc[255]       ="\0";
index b526581798d8138924fda32703467211840552b2..88717f1a48ebfe75be073881245c1eccb9f72845 100644 (file)
 
  */
 
+#include <QtCore/QByteArray>
+#include <QtCore/QDebug>
+#include <QtCore/QFile>
+#include <QtCore/QTextCodec>
+#include <QtCore/QXmlStreamAttributes>
+#include <QtCore/QXmlStreamReader>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 #include "cet_util.h"
-#include <QtCore/QDebug>
-#include <QtCore/QXmlStreamReader>
-#include <QtCore/QFile>
 
 #define DEBUG_TAG 0
 #if DEBUG_TAG
 #include <QtCore/QDebug>
 #endif
 
-#if HAVE_LIBEXPAT
-#include <expat.h>
-static XML_Parser psr;
-#endif
-
 static QString current_tag;
-static vmem_t cdatastr;
-static gbfile* ifd;
 static xg_tag_mapping* xg_tag_tbl;
-static const char** xg_ignore_taglist;
+static QSet<QString> xg_ignore_taglist;
+
+static const char* rd_fname;
+static QByteArray reader_data;
+static const char* xg_encoding;
+static QTextCodec* utf8_codec = QTextCodec::codecForName("UTF-8");
+static QTextCodec* codec = utf8_codec;  // Qt has no vanilla ASCII encoding =(
 
 #define MY_CBUF 4096
 
@@ -54,9 +57,14 @@ write_xml_header(gbfile* ofd)
 
   if ((global_opts.charset != NULL) && (global_opts.charset != cs)) {
     snprintf(buff, sizeof(buff), " encoding=\"%s\"", global_opts.charset_name);
+    QTextCodec* tcodec = QTextCodec::codecForName(global_opts.charset_name);
+    if (tcodec) {
+      codec = tcodec;
+    }
   } else {
     buff[0] = 0;
   }
+
   gbfprintf(ofd, "<?xml version=\"1.0\"%s?>\n", buff);
 }
 
@@ -64,8 +72,9 @@ void
 write_xml_entity(gbfile* ofd, const QString& indent,
                  const QString& tag, const QString& value)
 {
-  char* tmp_ent = xml_entitize(value.toLatin1().data());
-  gbfprintf(ofd, "%s<%s>%s</%s>\n", qPrintable(indent), qPrintable(tag), tmp_ent, qPrintable(tag));
+  char* tmp_ent = xml_entitize(CSTRE(value));
+  gbfprintf(ofd, "%s<%s>%s</%s>\n", CSTRE(indent), CSTRE(tag), tmp_ent,
+          CSTRE(tag));
   xfree(tmp_ent);
 }
 
@@ -82,7 +91,7 @@ void
 write_xml_entity_begin0(gbfile* ofd, const QString& indent,
                         const QString& tag)
 {
-  gbfprintf(ofd, "%s<%s>\n", indent.toLatin1().data(), tag.toLatin1().data());
+  gbfprintf(ofd, "%s<%s>\n", CSTRE(indent), CSTRE(tag));
 }
 
 void
@@ -90,7 +99,8 @@ write_xml_entity_begin1(gbfile* ofd, const QString& indent,
                         const QString& tag, const QString& attr,
                         const QString& attrval)
 {
-  gbfprintf(ofd, "%s<%s %s=\"%s\">\n", indent.toLatin1().data(), tag.toLatin1().data(), attr.toLatin1().data(), attrval.toLatin1().data());
+  gbfprintf(ofd, "%s<%s %s=\"%s\">\n", CSTRE(indent), CSTRE(tag), CSTRE(attr),
+      CSTRE(attrval));
 }
 
 void
@@ -99,14 +109,15 @@ write_xml_entity_begin2(gbfile* ofd, const QString& indent,
                         const QString& attrval1, const QString& attr2,
                         const QString& attrval2)
 {
-  gbfprintf(ofd, "%s<%s %s=\"%s\" %s=\"%s\">\n", indent.toLatin1().data(), tag.toLatin1().data(), attr1.toLatin1().data(), attrval1.toLatin1().data(), attr2.toLatin1().data(), attrval2.toLatin1().data());
+  gbfprintf(ofd, "%s<%s %s=\"%s\" %s=\"%s\">\n", CSTRE(indent), CSTRE(tag),
+      CSTRE(attr1), CSTRE(attrval1), CSTRE(attr2), CSTRE(attrval2));
 }
 
 void
 write_xml_entity_end(gbfile* ofd, const QString& indent,
                      const QString& tag)
 {
-  gbfprintf(ofd, "%s</%s>\n", indent.toLatin1().data(), tag.toLatin1().data());
+  gbfprintf(ofd, "%s</%s>\n", CSTRE(indent), CSTRE(tag));
 }
 
 void
@@ -114,7 +125,7 @@ xml_write_time(gbfile* ofd, gpsbabel::DateTime dt, const char* elname)
 {
   gbfprintf(ofd, "<%s>%s</%s>\n",
             elname,
-            dt.toPrettyString().toUtf8().data(),
+            CSTRE(dt.toPrettyString()),
             elname
            );
 }
@@ -141,282 +152,140 @@ xml_tbl_lookup(const QString& tag, xg_cb_type cb_type)
   return NULL;
 }
 
-/*
- * See if tag element 't' is in our list of things to ignore.
- * Returns 0 if it is not on the list.
- */
-static int
-xml_consider_ignoring(const char* t)
+void
+xml_init(const char* fname, xg_tag_mapping* tbl, const char* encoding)
 {
-  const char** il;
-
-  if (!xg_ignore_taglist) {
-    return 0;
-  }
-
-  for (il = xg_ignore_taglist; *il; il++) {
-    if (0 == strcmp(*il, t)) {
-      return 1;
+  rd_fname = fname;
+  xg_tag_tbl = tbl;
+  xg_encoding = encoding;
+  if (encoding) {
+    QTextCodec *tcodec = QTextCodec::codecForName(encoding);
+    if (tcodec) {
+      codec = tcodec;
     }
   }
-  return 0;
 }
 
-
-static void
-xml_start(void* data, const XML_Char* xml_el, const XML_Char** xml_attr)
+void
+xml_deinit(void)
 {
-  xg_callback* cb;
-  const char* el;
-  const char** attrs;
-
-  el = xml_convert_to_char_string(xml_el);
-  attrs = xml_convert_attrs_to_char_string(xml_attr);
-
-  if (xml_consider_ignoring(el)) {
-    return;
-  }
-
-  current_tag.append("/");
-  current_tag.append(el);
-
-  memset(cdatastr.mem, 0, cdatastr.size);
-
-  cb = xml_tbl_lookup(current_tag, cb_start);
-  if (cb) {
-#if DEBUG_TAG
-    fprintf(stderr, "Start: %s\n", xml_el);
-#endif
-    (*cb)(NULL, attrs);
-  }
-  xml_free_converted_string(el);
-  xml_free_converted_attrs(attrs);
+  reader_data.clear();
+  rd_fname = NULL;
+  xg_tag_tbl = NULL;
+  xg_encoding = NULL;
+  codec = utf8_codec;
 }
 
-#if 1
-static void
-xml_cdata(void* dta, const XML_Char* xml_s, int len)
+static bool
+xml_consider_ignoring(const QStringRef& name)
 {
-  char* estr;
-  const char* s = xml_convert_to_char_string_n(xml_s, &len);
-
-  vmem_realloc(&cdatastr,  1 + len + strlen(cdatastr.mem));
-  estr = (char*) cdatastr.mem + strlen(cdatastr.mem);
-  memcpy(estr, s, len);
-  estr[len]  = 0;
-  xml_free_converted_string(s);
+  return xg_ignore_taglist.contains(name.toString());
 }
 
 static void
-xml_end(void* data, const XML_Char* xml_el)
+xml_run_parser(QXmlStreamReader& reader, QString& current_tag)
 {
-  int pos = current_tag.lastIndexOf('/');
-  QString s = current_tag.mid(pos + 1);
-  const char* el = xml_convert_to_char_string(xml_el);
   xg_callback* cb;
+  bool started = false;
 
-  if (xml_consider_ignoring(el)) {
-    return;
-  }
-
-  if (s.compare(el)) {
-    fprintf(stderr, "Mismatched tag %s\n", el);
-  }
-#if DEBUG_TAG
-  qDebug() << current_tag;
-#endif
-  cb = xml_tbl_lookup(current_tag, cb_cdata);
-  if (cb) {
-    (*cb)((char*) cdatastr.mem, NULL);
-  }
-
-  cb = xml_tbl_lookup(current_tag, cb_end);
-  if (cb) {
-    (*cb)(el, NULL);
-  }
-  current_tag.truncate(pos);
-  xml_free_converted_string(el);
-}
-
-void xml_read(void)
-{
-  int len;
-  char buf[MY_CBUF];
-
-  while ((len = gbfread(buf, 1, sizeof(buf), ifd))) {
-    char* str = buf;
-    if (ifd->unicode) {
-      str = cet_str_uni_to_utf8((short*)&buf, len >> 1);
-      len = strlen(str);
-    }
-    if (!XML_Parse(psr, str, len, gbfeof(ifd))) {
-      fatal(MYNAME ":Parse error at %d: %s\n",
-            (int) XML_GetCurrentLineNumber(psr),
-            XML_ErrorString(XML_GetErrorCode(psr)));
-    }
-    if (str != buf) {
-      xfree(str);
-    }
-  }
-  XML_ParserFree(psr);
-
-}
-
-void xml_readstring(char* str)
-{
-  int len = strlen(str);
-  if (!XML_Parse(psr, str, len, 1)) {
-    fatal(MYNAME ":Parse error at %d: %s\n",
-          (int) XML_GetCurrentLineNumber(psr),
-          XML_ErrorString(XML_GetErrorCode(psr)));
-  }
-  XML_ParserFree(psr);
-}
-
-void xml_readprefixstring(const char* str)
-{
-  int len = strlen(str);
-  if (!XML_Parse(psr, str, len, 0)) {
-    fatal(MYNAME ":Parse error at %d: %s\n",
-          (int) XML_GetCurrentLineNumber(psr),
-          XML_ErrorString(XML_GetErrorCode(psr)));
-  }
-}
-
-void xml_ignore_tags(const char** taglist)
-{
-  xg_ignore_taglist = taglist;
-}
-
-void
-xml_init0(const char* fname, xg_tag_mapping* tbl, const char* encoding,
-          gbsize_t offset)
-{
-  if (fname) {
-    ifd = gbfopen(fname, "r", MYNAME);
-    if (offset) {
-      gbfseek(ifd, offset, SEEK_SET);
-    }
-  } else {
-    ifd = NULL;
-  }
+  while (!reader.atEnd()) {
+    switch (reader.tokenType()) {
+    case QXmlStreamReader::StartDocument:
+      if (!reader.documentEncoding().isEmpty()) {
+        codec = QTextCodec::codecForName( CSTR(reader.documentEncoding().toString()) );
+      }
+      if (codec == NULL) {
+        // According to http://www.opentag.com/xfaq_enc.htm#enc_default , we
+        // should assume UTF-8 in absense of other informations. Users can
+        // EASILY override this with xml_init().
+        codec = QTextCodec::codecForName("UTF-8");
+      }
+      started = true;
+      break;
 
-  current_tag.clear();
+    case QXmlStreamReader::StartElement:
+      if (xml_consider_ignoring(reader.name())) {
+        goto readnext;
+      }
 
-  psr = XML_ParserCreate((const XML_Char*)encoding);
-  if (!psr) {
-    fatal(MYNAME ": Cannot create XML Parser\n");
-  }
+      current_tag.append("/");
+      current_tag.append(reader.qualifiedName());
 
-  cdatastr = vmem_alloc(1, 0);
-  *((char*)cdatastr.mem) = '\0';
+      cb = xml_tbl_lookup(current_tag, cb_start);
+      if (cb) {
+        const QXmlStreamAttributes attrs = reader.attributes();
+        cb(NULL, &attrs);
+      }
 
-  xg_tag_tbl = tbl;
+      cb = xml_tbl_lookup(current_tag, cb_cdata);
+      if (cb) {
+        QString c = reader.readElementText(QXmlStreamReader::IncludeChildElements);
+        cb(CSTRE(c), NULL);
+        current_tag.chop(reader.qualifiedName().length() + 1);
+      }
+      break;
 
-  cet_convert_init(CET_CHARSET_UTF8, 1);
+    case QXmlStreamReader::EndElement:
+      if (xml_consider_ignoring(reader.name())) {
+        goto readnext;
+      }
 
-  XML_SetUnknownEncodingHandler(psr, cet_lib_expat_UnknownEncodingHandler, NULL);
-  XML_SetElementHandler(psr, xml_start, xml_end);
-  XML_SetCharacterDataHandler(psr, xml_cdata);
-}
+      cb = xml_tbl_lookup(current_tag, cb_end);
+      if (cb) {
+        cb(CSTRE(reader.name().toString()), NULL);
+      }
+      current_tag.chop(reader.qualifiedName().length() + 1);
+      break;
 
-/* xml_init0 iwth a default seek argument of zero */
-void
-xml_init(const char* fname, xg_tag_mapping* tbl, const char* encoding)
-{
-  xml_init0(fname, tbl, encoding, 0);
-}
+    case QXmlStreamReader::Characters:
+      break;
 
-void
-xml_init_offset(const char* fname, xg_tag_mapping* tbl, const char* encoding,
-                gbsize_t offset)
-{
-  xml_init0(fname, tbl, encoding, offset);
-}
+    default:
+      break;
+    };
 
-void
-xml_deinit(void)
-{
-  vmem_free(&cdatastr);
-  if (ifd) {
-    gbfclose(ifd);
-    ifd = NULL;
+readnext:
+    if (started) {
+      reader.readNextStartElement();
+    } else {
+      reader.readNext();
+    }
   }
-  xg_ignore_taglist = NULL;
-}
-
-#else
-
-static const char* rd_fname;
-static QXmlStreamReader reader;
-
-void
-xml_init(const char* fname, xg_tag_mapping* tbl, const char* encoding)
-{
-  rd_fname = fname;
-  xg_tag_tbl = tbl;
 }
 
 void xml_read(void)
 {
   QFile file(rd_fname);
+  QString current_tag;
+
   file.open(QIODevice::ReadOnly);
-  reader.setDevice(&file);
 
-  QString current_tag;
-  while (!reader.atEnd()) {
-    switch (reader.tokenType()) {
-    case QXmlStreamReader::StartElement: {
-      current_tag.append("/");
-      current_tag.append(reader.name());
-      xg_callback* cb = xml_tbl_lookup(current_tag, cb_start);
-      if (cb) {
-        const char** attrs;
-        (*cb)(NULL, attrs);
-      }
-      cb = xml_tbl_lookup(current_tag, cb_cdata);
-      if (cb) {
-        QString c = reader.readElementText();
-        (*cb)(c.toUtf8().data(), NULL);
-        current_tag.chop(reader.name().length() + 1);
-      }
-    }
-    break;
-    case QXmlStreamReader::Characters:
-      break;
-    case QXmlStreamReader::EndElement: {
-      xg_callback* cb = xml_tbl_lookup(current_tag, cb_end);
-      if (cb) {
-        (*cb)(NULL, NULL);
-      }
-      current_tag.chop(reader.name().length() + 1);
-    }
-    break;
-    default:
-      break;
-    };
-    reader.readNextStartElement();
-  }
+  QXmlStreamReader reader(&file);
 
+  xml_run_parser(reader, current_tag);
 }
 
 void xml_ignore_tags(const char** taglist)
 {
-  xg_ignore_taglist = taglist;
+  for (; taglist && *taglist; taglist++) {
+    xg_ignore_taglist.insert(QString::fromUtf8(*taglist));
+  }
 }
 
 void xml_readprefixstring(const char* str)
 {
+  reader_data.append(str);
 }
 
-void xml_readstring(char* str)
+void xml_readstring(const char* str)
 {
-}
+  QString current_tag;
 
-void
-xml_deinit(void)
-{
+  reader_data.append(str);
+
+  QXmlStreamReader reader(reader_data);
+
+  xml_run_parser(reader, current_tag);
 }
-#endif
 
 /******************************************/
index 1107922a2daf188c34257e9069b3272ed8aee639..c725724a34ca1b8bcf2d188887c8c1b45ab74a96 100644 (file)
@@ -27,7 +27,7 @@ typedef enum {
   cb_end,
 } xg_cb_type;
 
-typedef void (xg_callback)(const char*, const char**);
+typedef void (xg_callback)(const char*, const QXmlStreamAttributes*);
 
 typedef struct xg_tag_mapping {
   xg_callback* tag_cb;
@@ -59,6 +59,6 @@ void xml_init(const char* fname, xg_tag_mapping* tbl,const char* encoding);
 void xml_init_offset(const char* fname, xg_tag_mapping* tbl,
                      const char* encoding, gbsize_t offset);
 void xml_read(void);
-void xml_readstring(char* str);
+void xml_readstring(const char* str);
 void xml_readprefixstring(const char* str);
 void xml_deinit(void);
index ff8418b3b5fc34195b02f9fe27122a8f5a21b9ce..12eb92d5caaddcd708f62664d01241d2ea199cc7 100644 (file)
@@ -20,6 +20,8 @@
 
 */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 #include "jeeps/gpsmath.h"
@@ -38,20 +40,6 @@ static arglist_t xol_args[] = {
 
 #define MYNAME "xol"
 
-#if ! HAVE_LIBEXPAT
-void
-xol_rd_init(const char *fname)
-{
-  fatal(MYNAME ": This build excluded \"" MYNAME "\" support because expat was not installed.\n");
-}
-
-void
-xol_read(void)
-{
-}
-
-#else
-
 static xg_callback     xol_shape, xol_shape_end;
 static xg_callback     xol_waypt, xol_overlay;
 
@@ -68,64 +56,57 @@ xg_tag_mapping xol_map[] = {
 
 
 static void
-xol_overlay(const char *args, const char **attrv)
+xol_overlay(const char *args, const QXmlStreamAttributes* attrv)
 {
-  const char **avp = &attrv[0];
-
-  while (*avp) {
-    if (strcmp(avp[0], "version") == 0) {
-      if (strcmp(avp[1], "1.0") != 0) {
-        fatal(MYNAME ": Unsupported version %s.\n", avp[1]);
-      }
+  if (attrv->hasAttribute("version")) {
+    if (attrv->value("version") != "1.0") {
+      fatal(MYNAME ": Unsupported version %s.\n",
+            attrv->value("version").toString().toUtf8().constData());
     }
-
-    avp+=2;
   }
 }
 
 static void
-xol_shape(const char *args, const char **attrv)
+xol_shape(const char *args, const QXmlStreamAttributes* attrv)
 {
-  const char **avp = &attrv[0];
-
-  while (*avp) {
-    if (strcmp(avp[0], "type") == 0) {
-      if (strcmp(avp[1], "waypoint") == 0) {
-        wpt = waypt_new();
-      } else if (strcmp(avp[1], "polyline") == 0) {
-        trk = route_head_alloc();
-        track_add_head(trk);
-      }
-    } else if (strcmp(avp[0], "name") == 0) {
-      if (wpt) {
-        wpt->shortname = xstrdup(avp[1]);
-      } else if (trk) {
-        trk->rte_name = xstrdup(avp[1]);
-      }
-    } else if (strcmp(avp[0], "comment") == 0) {
-      if (wpt) {
-        wpt->notes = xstrdup(avp[1]);
-      }
-    } else if (strcmp(avp[0], "alt") == 0) {
-      if (wpt) {
-        wpt->altitude = atof(avp[1]);
-      }
-    } else if (strcmp(avp[0], "timestamp") == 0) {
-      if (wpt) {
-        wpt->creation_time = xml_parse_time(avp[1]);
-      }
-    } else if (strcmp(avp[0], "icon") == 0) {
-      if (wpt) {
-        wpt->icon_descr = avp[1];
-      }
+  if (attrv->hasAttribute("type")) {
+    if (attrv->value("type") == "waypoint") {
+      wpt = waypt_new();
+    } else if (attrv->value("type") == "polyline") {
+      trk = route_head_alloc();
+      track_add_head(trk);
+    }
+  }
+
+  if (attrv->hasAttribute("name")) {
+    if (wpt) {
+      wpt->shortname = xstrdup(attrv->value("name").toString().toUtf8().constData());
+    } else if (trk) {
+      trk->rte_name = xstrdup(attrv->value("name").toString().toUtf8().constData());
+    }
+  }
+
+  if (wpt) {
+    if (attrv->hasAttribute("comment")) {
+      wpt->notes = xstrdup(attrv->value("comment").toString().toUtf8().constData());
+    }
+
+    if (attrv->hasAttribute("alt")) {
+      wpt->altitude = attrv->value("alt").toString().toDouble();
     }
 
-    avp+=2;
+    if (attrv->hasAttribute("timestamp")) {
+      wpt->creation_time = xml_parse_time(attrv->value("timestamp").toString().toUtf8().constData());
+    }
+
+    if (attrv->hasAttribute("icon")) {
+      wpt->icon_descr = xstrdup(attrv->value("icon").toString().toUtf8().constData());
+    }
   }
 }
 
 static void
-xol_shape_end(const char *args, const char **unused)
+xol_shape_end(const char *args, const QXmlStreamAttributes* unused)
 {
   if (wpt) {
     if (trk) {
@@ -143,18 +124,16 @@ xol_shape_end(const char *args, const char **unused)
 }
 
 static void
-xol_waypt(const char *args, const char **attrv)
+xol_waypt(const char *args, const QXmlStreamAttributes* attrv)
 {
-  const char **avp = &attrv[0];
   int x=0, y=0;
 
-  while (*avp) {
-    if (strcmp(avp[0], "y") == 0) {
-      y = atoi(avp[1]);
-    } else if (strcmp(avp[0], "x") == 0) {
-      x = atoi(avp[1]);
-    }
-    avp+=2;
+  if (attrv->hasAttribute("y")) {
+    y = attrv->value("y").toString().toInt();
+  }
+
+  if (attrv->hasAttribute("x")) {
+    x = attrv->value("x").toString().toInt();
   }
 
   GPS_Math_Swiss_EN_To_WGS84((double)x, (double)y, &wpt->latitude, &wpt->longitude);
@@ -175,8 +154,6 @@ xol_read(void)
   xml_read();
 }
 
-#endif
-
 static void
 xol_rd_deinit(void)
 {
index e55e00a6fd6f001f70c49c37c6fbc042802df200..c5f00b301ecd2389fa9b089c84feb7d712a6986e 100644 (file)
@@ -19,6 +19,8 @@
 
  */
 
+#include <QtCore/QXmlStreamAttributes>
+
 #include "defs.h"
 #include "xmlgeneric.h"
 
@@ -77,28 +79,28 @@ yahoo_wr_init(const char *fname)
   fatal("Writing file of type %s is not supported\n", MYNAME);
 }
 
-void   wpt_s(const char *args, const char **unused)
+void   wpt_s(const char *args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp = waypt_new();
 }
 
-void   wpt_e(const char *args, const char **unused)
+void   wpt_e(const char *args, const QXmlStreamAttributes* unused)
 {
   waypt_add(wpt_tmp);
   wpt_tmp = NULL;
 }
 
-void   wpt_lat(const char *args, const char **unused)
+void   wpt_lat(const char *args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->latitude = atof(args);
 }
 
-void   wpt_lon(const char *args, const char **unused)
+void   wpt_lon(const char *args, const QXmlStreamAttributes* unused)
 {
   wpt_tmp->longitude = atof(args);
 }
 
-void   wpt_addr(const char *args, const char **unused)
+void   wpt_addr(const char *args, const QXmlStreamAttributes* unused)
 {
   if (wpt_tmp->notes) {
     wpt_tmp->notes = xstrappend(wpt_tmp->notes, as);